Web Foundations WEDNESDAY, OCTOBER 2, 2013 LECTURE 5: INTRODUCTION TO CSS CONTINUED.

Download Web Foundations WEDNESDAY, OCTOBER 2, 2013 LECTURE 5: INTRODUCTION TO CSS CONTINUED.

Post on 12-Jan-2016

212 views

Category:

Documents

0 download

TRANSCRIPT

BIT112

Web FoundationsWednesday, October 2, 2013LECTURE 5: Introduction to CSS CONTINUED

HTML & CSS for Page LayoutAs we saw in a previous lecture, the semantic markup introduced in HTML5 allows to construct page layouts differently.

Although we still can use tags for creating layouts, many of the standard page elements such as header, navigation, footer have now their own tags. This does not change the way CSS and HTML work together but it makes our code more meaningful and saves us from typing some 's (we can still use divs to create "wrappers" to center sections, produce "responsive" pages, etc).NOTE: We will discuss "id" and "class" a bit later in today's lectureHTML & CSS for Page LayoutA basic layout uses a header, a main content area and a footer. On the HTML side there is nothing new except that we use might a div wrapper layer for centering the content in the browser.

This is the header Here would come the main content Last but not least, the footer NOTE: We will discuss "id" and "class" a bit later in today's lecture

Without the CSS, the web page looks pretty basic, even though all the HTML tags are in place. We'll use the CSS to jazz things up a bit.

CSS Syntax (Review) A CSS declaration always ends with a semicolon, and declaration groups are surrounded by curly brackets or "squiggles":

p {color:red; text-align:center;}4HTML & CSS for Page LayoutNow looking at the CSS, first we reset the margin and padding of all elements to zero and tell the browser to render all HTML5 section tags as block.* { margin:0px; padding:0px;} header, footer, section, aside, article, nav { display: block;}NOTE: We will discuss "id" and "class" a bit later in today's lectureHTML & CSS for Page LayoutThe wrapper centers the rest of the contentdiv#wrapper { width:90%; margin:0px auto;}NOTE: We will discuss "id" and "class" a bit later in today's lectureHTML & CSS for Page LayoutWhile we simply add some color to distinguish the three sections of the document: header, the main section and the footer.header { background-color:#CCA; height:50px;} section { background-color:#F3C200; height:100px;} footer { background-color:#CC6; height:20px;}NOTE: We will discuss "id" and "class" a bit later in today's lectureHTML & CSS for Page LayoutPutting it all together and the CSS render content of the now page looks like this:NOTE: We will discuss "id" and "class" a bit later in today's lecture

Demo code: test001.htmlCommentingSome notes about these CSS properties, attributes, and values:

First, commenting inside HTML and CSS

HTML Comment

CSS Comment

/* Comment Goes Here */Demo: HTML Comment in CCS Internal StyleThe id Selector: #Standards specify that any given id name can only be referenced once within a page or document. From my experience, ids are most commonly used correctly in CSS layouts. This makes sense because there are usually only one 'wrapper' per page, or only one menu, one banner, usually only one content pane, etc. What this means is, two selectors cannot us the same id. If you want to do that, then you would create and use a class (which we'll talk about a bit later). NOTE: Do NOT start an id name with a number! It will not work in Firefox.

In the CSS

div#wrapper {width:70%; sets width of div in relation to the browser margin:0px auto;}

In the HTML

. . .

Demo: ID in CCSThe margin PropertyThe margin clears an area around an element (outside the border). The margin does not have a background color, and is completely transparent. The top, right, bottom, and left margin can be changed independently using separate properties. A shorthand margin property can also be used, to change all margins at once.W3Schools: marginThe margin property can have from one to four values:

margin:25px 50px 75px 100px; top margin is 25pxright margin is 50pxbottom margin is 75pxleft margin is 100px

margin:25px 50px 75px; top - right/left - bottomtop margin is 25pxright and left margins are 50pxbottom margin is 75px

margin:25px 50px; top/bottom - right/lefttop and bottom margins are 25pxright and left margins are 50px

margin:25px;all four margins are 25pxmargin-top:100px;margin-bottom:100px;margin-right:50px;margin-left:50px;The height PropertyThe height property sets the height of an element, whether in by auto (default), length (px, cm, pt, etc).

height:50px;W3Schools: heightThe background-color PropertyThe background-color property sets the background color of an element.

background-color:#CCA; or #CCCCAAW3Schools: background-colorThe class Selector: .The class selector is used to specify a style for a group of elements. Unlike the id selector, the class selector is most often used on several elements. This allows you to set a particular style for many HTML elements with the same class. The class selector is defined with a period or "dot": . NOTE: You can name a class anything you want, although it is recommended you give it a name according to its function.

In the example below, all HTML elements with class="center" will be center-aligned:

In the CSS

.center {text-align:center;}

In the HTML

Rex Winkus's PortfolioWeek 01W3Schools: Class vs IDThe class Selector, specified by a HTML ElementYou can also specify that only predetermined HTML elements should be affected by a class. In other words, even if other elements call a class by name, only the type of element uniquely specified will be affected by the call.

In the CSS

p.center{text-align:center;}

In the HTML

This heading will not be affectedThis paragraph will be center-aligned.W3Schools: Class vs IDhttp://www.htmldog.com/guides/css/intermediate/classid/Some Other Basic CSS Properties: font-familyIn the CSS [remember, that these class names can be anything you want]

p.serif{font-family:"Times New Roman",Times,serif;}p.sansserif{font-family:Arial,Helvetica,sans-serif;}

In the HTML

This is heading 1 This isn't affectedThis is heading 2 This isn't affectedThis is a paragraph.This is a paragraph.

W3Schools: font-familySome Other Basic CSS Properties: font-sizeIn the CSS

h1 {font-size:250%;}h2 {font-size:200%;}.ften {font-size:10pt;}.f875em {font-size:0.875em;}

In the HTML

This is heading 1This is heading 2This is a paragraph.This is a paragraph.This is a paragraph.

W3Schools: font-sizeAn "em" is a relative property based on the default font-size of the browsers, which is typically 16px. For example, this means that:

1em = (16 x 1) = 16px = 100% 1.25em (16 x 1.25) = 20px = 125%0.75em (16 x 0.75) = 12px = 75%2em (16 x 2) = 32px = 200%

Some Other Basic CSS Properties: font-styleIn the CSS [remember, that these class names can be anything you want]

.normal {font-style:normal;}p.italic {font-style:italic;}.oblique {font-style:oblique;}

In the HTML

This is a paragraph, normal.This is a paragraph, italic.This is a paragraph, oblique.This is a heading1, oblique.

W3Schools: font-styleSome Other Basic CSS Properties: font-variantIn the CSS [remember, that these class names can be anything you want]

.normal {font-variant:normal;}.small {font-variant:small-caps;}

In the HTML

Rex Winkus's PortfolioMy name is Rex Winkus.My name is Rex Winkus.

W3Schools: font-variantSome Other Basic CSS Properties: font-weightIn the CSS [remember, that these class names can be anything you want]

p.normal {font-weight:normal;}p.light {font-weight:lighter;}p.thick {font-weight:bold;}p.thicker {font-weight:900;}

In the HTML

This is a paragraph.This is a paragraph.This is a paragraph.This is a paragraph.

W3Schools: font-weightValueDescriptionnormalDefault. Defines normal charactersboldDefines thick charactersbolderDefines thicker characterslighterDefines lighter characters100200300400500600700800900Defines from thin to thick characters. 400 is the same as normal, and 700 is the same as boldSome Other Basic CSS Properties: font (shorthand property)The font shorthand property sets all the font properties in one declaration. The properties that can be set, are (in order): "font-style font-variant font-weight font-size/line-height font-family". The font-size and font-family values are required. If one of the other values are missing, the default values will be inserted, if any.

In the CSS [remember, that these class names can be anything you want]

.ex1{font:15px arial,sans-serif;}p.ex2{font:italic bold 12px/30px Georgia,serif;}

In the HTML

Rex Winkus's PortfolioMy name is Rex Winkus.My name is Rex Winkus.My name is Rex Winkus. This is not altered

W3Schools: font (shorthand)Some Other Basic CSS Properties: line-heightThe line-height property specifies the line height.

In the CSS [remember, that these class names can be anything you want]

p.normal{line-height:100%} 100% of normal, or 16pxp.small {line-height:90%} 90% of normal, or 14.4pxp.big {line-height:2} twice normal line height, or 32pxp.reallybig {line-height:48px} three times normal line height, or 3

In the HTML

Rex Winkus's PortfolioMy name is Rex Winkus.My name is Rex Winkus.My name is Rex Winkus. This is not altered

W3Schools: line-heightSome Other Basic CSS Properties: text-decorationThe text-decoration property specifies the decoration added to text.

In the CSS [remember, that the class names can be anything you want]

h1 {text-decoration:overline;}h2 {text-decoration:line-through;}h3 {text-decoration:underline;}.none {text-decoration:none;}

In the HTML

This is heading 1This is heading 2This is heading 3Google

W3Schools: text-decorationSome Other Basic CSS Properties: text-alignThe text-align property specifies the horizontal alignment of text in an element.

In the CSS

h1 {text-align:center}h2 {text-align:left}h3 {text-align:right}

In the HTML

This is heading 1This is heading 2This is heading 3W3Schools: text-alignValueDescriptionleftAligns to the leftrightAligns to the rightcenterCenters the textjustifystretches the lines so each line has equal widthSome Other Basic CSS Properties: text-transformThe text-transform property controls the capitalization of text.

In the CSS

h1 {text-transform:uppercase;}h2 {text-transform:capitalize;}p {text-transform:lowercase;}

In the HTML

This is some text.This is some text.This is some text.W3Schools: text-transformValueDescriptionnoneNo capitalization. The text renders as it is (this is the default)capitalizeTransforms the first character of each word to uppercaseuppercaseTransforms all characters to uppercaselowercaseTransforms all characters to lowercaseSome Other Basic CSS Properties: colorThe color property specifies the color of text.

In the CSS

body {color:red;}h1 {color:#00ff00;}p.ex {color:rgb(0,0,255);}

In the HTML

This is heading 1This is an ordinary paragraph. Notice that this text is red. The default text-color for a page is defined in the body selector.This is a paragraph with class="ex". This text is blue.W3Schools: colorValueDescriptioncolorSpecifies the text color. Look at CSS Color Values for a complete list of possible color values.inheritSpecifies that the color should be inherited from the parent element

Recommended

View more >