advanced cascading style sheets

111
Advanced Advanced CSS CSS by: by: Alexandra Vlachakis Alexandra Vlachakis Sandy Creek High School, Fayette County Schools Sandy Creek High School, Fayette County Schools Content and Resources Used With Permission: Content and Resources Used With Permission: Interact With Web Standards. Copyright 2010. Interact With Web Standards. Copyright 2010. Erin Anderson et. Al. Erin Anderson et. Al. W3 Schools. www.w3schools.com. 12-25-11. W3 Schools. www.w3schools.com. 12-25-11.

Upload: fantasticdigitaltools

Post on 27-Jan-2015

120 views

Category:

Education


4 download

DESCRIPTION

Advanced CSSby: Alexandra VlachakisSandy Creek High School, Fayette County SchoolsSlide Show correlates Georgia Deparment of Edcuation Career and Technology PATHWAY: Interactive MediaCOURSE: Advanced Web DesignUNIT 6: BCS-AWD-6 Advanced CSS

TRANSCRIPT

Page 1: Advanced Cascading Style Sheets

Advanced Advanced CSSCSS

by: by: Alexandra VlachakisAlexandra VlachakisSandy Creek High School, Fayette County SchoolsSandy Creek High School, Fayette County Schools

Content and Resources Used With Permission: Content and Resources Used With Permission: Interact With Web Standards. Copyright 2010. Interact With Web Standards. Copyright 2010.

Erin Anderson et. Al.Erin Anderson et. Al.W3 Schools. www.w3schools.com. 12-25-11. W3 Schools. www.w3schools.com. 12-25-11.

Page 2: Advanced Cascading Style Sheets

Instructors Note:

► The following 9 slides are review from the BCS_FWD_6_UNITPLAN_IntroductionToCSS

► Depending on your students knowledge of CSS you will need to review some or all of the content included in the following slides.

► It is also a good idea to give students the test at the end of BCS_FWD_6_UNITPLAN_IntroductionToCSS Unit as a pre-test to assess student mastery level.

Page 3: Advanced Cascading Style Sheets

CSS ReviewCSS Review

Page 4: Advanced Cascading Style Sheets

Selector ReviewSelector Review

Definition: identifies the HTML elements Definition: identifies the HTML elements that the rule will be applied to, identified that the rule will be applied to, identified by the actual element name, e.g. by the actual element name, e.g. <body>, or by other means such as <body>, or by other means such as classclass attribute values. attribute values.

Example:Example:

*The selector is normally the HTML element you want to style

Page 5: Advanced Cascading Style Sheets

Selector ReviewSelector Review

selector {property:value}selector {property:value}

body {color: black}body {color: black}

If  the value is multiple words, put quotes around the value If  the value is multiple words, put quotes around the value

p {font-family:"sans serif"}p {font-family:"sans serif"}

If you want to specify more than one property, you must If you want to specify more than one property, you must separate each property with a semicolon. The example separate each property with a semicolon. The example below shows how to define a center aligned paragraph, below shows how to define a center aligned paragraph, with a red text colorwith a red text color

p {text-align:center;color:red}p {text-align:center;color:red}

Page 6: Advanced Cascading Style Sheets

• To make the style definitions more readable, you To make the style definitions more readable, you can describe one property on each line, like this:can describe one property on each line, like this:

pp{ { text-align:center;text-align:center;

color:black;color:black;font-family:arial font-family:arial

}}

Selector ReviewSelector Review

Page 7: Advanced Cascading Style Sheets

Property & Value ReviewProperty & Value Review

Definition: Definition: The property is the style attribute you want to change. Each property has a value.

*Properties are separated from their respective values *Properties are separated from their respective values by by colons colons ::*Pairs are separated from each other by Pairs are separated from each other by semicolons semicolons ;;

Page 8: Advanced Cascading Style Sheets

Declaration ReviewDeclaration Review

Definition: Each CSS line that includes Definition: Each CSS line that includes property and valueproperty and value

*Each declaration consists of a property and a value.

Page 9: Advanced Cascading Style Sheets

Style Sheets ReviewStyle Sheets Review

• When a browser reads a style sheet, When a browser reads a style sheet, it will format the document it will format the document according to it. There are three ways according to it. There are three ways of inserting a style sheet:of inserting a style sheet:• External Style Sheet External Style Sheet • Internal Style SheetInternal Style Sheet• Inline StylesInline Styles

Instructor Note: Students will be using External Style Instructor Note: Students will be using External Style Sheets for all the lesson that followSheets for all the lesson that follow

Page 10: Advanced Cascading Style Sheets

Class Selectors ReviewClass Selectors ReviewClass Class -- The class selector is used to specify a style for a The class selector is used to specify a style for a

group of elements. Unlike the id selector, the class group of elements. Unlike the id selector, the class selector is most often used on several elements. selector is most often used on several elements.

This allows you to set a particular style for any HTML This allows you to set a particular style for any HTML elements with the same class. elements with the same class.

The class selector uses the HTML class attribute, and The class selector uses the HTML class attribute, and is defined with a "." is defined with a "."

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

.center {text-align:center;}.center {text-align:center;}

Page 11: Advanced Cascading Style Sheets

id Selectors Reviewid Selectors Review In addition to setting a style for a HTML element, In addition to setting a style for a HTML element,

CSS allows you to specify your own selectors called CSS allows you to specify your own selectors called "id" and "class"."id" and "class".

idid - - The id selector is used to specify a style for a single, The id selector is used to specify a style for a single, unique element. unique element.

The id selector uses the id attribute of the HTML The id selector uses the id attribute of the HTML element, and is defined with a "#". element, and is defined with a "#".

The style rule below will be applied to the element The style rule below will be applied to the element with id="para1": with id="para1":

#para1 {text-align:center;color:red;}#para1 {text-align:center;color:red;}

Page 12: Advanced Cascading Style Sheets

Class and id Selectors Class and id Selectors ReviewReview

In the image below what is the h1 In the image below what is the h1 selector an ID or a Class?selector an ID or a Class?

#

.

Page 13: Advanced Cascading Style Sheets

How well do you know CSS?How well do you know CSS?

► What are CSS style sheets?What are CSS style sheets?► Why do web developers use CSS style sheets?Why do web developers use CSS style sheets?► What are the components of a CSS rule?What are the components of a CSS rule?► What is the difference between using a CSS ID and What is the difference between using a CSS ID and

Class?Class?► Why do web developers use CSS comments?Why do web developers use CSS comments?► How do you apply an internal CSS style?How do you apply an internal CSS style?► How do you apply an external CSS style sheet?How do you apply an external CSS style sheet?► How do you apply an inline CSS style?How do you apply an inline CSS style?► What is the CSS rule for applying colors?What is the CSS rule for applying colors?► What are the units of measurement used to specify What are the units of measurement used to specify

size and dimension in CSS?size and dimension in CSS?

Page 14: Advanced Cascading Style Sheets

End ReviewEnd Review

►The next slides are new content. The next slides are new content. ► If students need more review on CSS If students need more review on CSS

please see Unit 6 Introduction To CSSplease see Unit 6 Introduction To CSS

Page 15: Advanced Cascading Style Sheets

Lesson 1: Lesson 1:

Alpha or Transparent Alpha or Transparent ColorsColors

Page 16: Advanced Cascading Style Sheets

►AlphaAlpha –RGB(a) has the ability to make –RGB(a) has the ability to make items transparent (or see-through)items transparent (or see-through)

►The “a” stands for alpha which means The “a” stands for alpha which means transparency.transparency.

►Opposite of alpha is opacity which the Opposite of alpha is opacity which the measurement of how solid a color is.measurement of how solid a color is.

►CSS example: CSS example: ►div{color: RGBa(255,0,0, 0.7) }div{color: RGBa(255,0,0, 0.7) }

Lesson 1: Lesson 1: Alpha or Alpha or Transparent ColorsTransparent Colors

Page 17: Advanced Cascading Style Sheets

Lesson 1 Assignment Part 1 of 2:Lesson 1 Assignment Part 1 of 2:CSS Alpha Color HTML PageCSS Alpha Color HTML Page

► Open A New Notepad DocumentOpen A New Notepad Document► Type the following Code.Type the following Code.<html><title> CSS Transparency Example </title><head> <link href="style.css" type="text/css" rel="stylesheet"></head><body>

<div >A stands for alpha which is another way of saying transparency. </div>

<div > You can also call it opacity, which is the opposite of transparency. Opacity is a measure of how solid a color is versus when something is completely transparent it can’t be seen at all.</div>

</body></html>► Save Your File as alpha-color.htmlSave Your File as alpha-color.html

Page 18: Advanced Cascading Style Sheets

Lesson 1 Assignment Part 2 of 2: Lesson 1 Assignment Part 2 of 2: CSS Alpha Color Style SheetCSS Alpha Color Style Sheet

► Open A New Notepad DocumentOpen A New Notepad Document► Type the following Code.Type the following Code.div{background-color:rgba(240,250,59,.8);width:800px;}► Save Your File as style.cssSave Your File as style.css► Open your Open your alpha-color.html web page. Check your alpha-color.html web page. Check your

new color application. Try other color combinations.new color application. Try other color combinations.► Browser Compatibility Note: Alpha color is not Browser Compatibility Note: Alpha color is not

compatible with IE8 or below but will work on compatible with IE8 or below but will work on Firefox.Firefox.

►Instructor Instructor Note: After Note: After creating the creating the file have file have students students manipulate manipulate the color the color values to values to discover other discover other color color combinations combinations using RGB(a)using RGB(a)

Page 19: Advanced Cascading Style Sheets

Lesson 2: Lesson 2: Block elementsBlock elements

Page 20: Advanced Cascading Style Sheets

Lesson 2: Lesson 2: Block elementsBlock elements

A block element is an element that takes up the full width A block element is an element that takes up the full width available, and has a line break before and after it.available, and has a line break before and after it.

Examples of block elements:Examples of block elements:<h1> <h1> <p> <p> <div><div> You should be familiar with <h1> and <p> tags from You should be familiar with <h1> and <p> tags from

HTMLHTML Can anyone tell us what they are used for?Can anyone tell us what they are used for? The <div> tag defines a division or a section in an HTML The <div> tag defines a division or a section in an HTML

document.document. The <div> tag is often used to group block-elements to The <div> tag is often used to group block-elements to

format them with styles.format them with styles. In the next assignment you will aligning <div> tags using In the next assignment you will aligning <div> tags using

CSSCSS

Page 21: Advanced Cascading Style Sheets

Lesson 2 Assignment:Lesson 2 Assignment:Div Tags & Block elementsDiv Tags & Block elements

► Open A New Notepad DocumentOpen A New Notepad Document► Create an external CSS style sheet & a HTML Document Create an external CSS style sheet & a HTML Document with 2 div with 2 div

tags, one <p>, 1 <h1> tag in HTML and 4 div tag styles with 4 tags, one <p>, 1 <h1> tag in HTML and 4 div tag styles with 4 different background colors in an external CSS style sheet. Set all the different background colors in an external CSS style sheet. Set all the block element widths = 800px.block element widths = 800px.

CSS Style Example:div{background-color:rgba(240,250,250,.8);Width=800px;}

HTML Example:<div> This box is a div tag box </div>► Save Your File as style.css in the same folder as your css-Save Your File as style.css in the same folder as your css-

block.html page. block.html page. ► Browser Compatibility Note rgb(a) does not work in IE8.

Page 22: Advanced Cascading Style Sheets

Lesson 3: Lesson 3: CSS PositioningCSS Positioning

Page 23: Advanced Cascading Style Sheets

Lesson 3: Lesson 3: CSS PositioningCSS Positioning

► The CSS positioning properties allow you to position The CSS positioning properties allow you to position an element like the ones we discussed in lesson 2.an element like the ones we discussed in lesson 2.

► It can also place an element behind another, and It can also place an element behind another, and specify what should happen when an element's specify what should happen when an element's content is too big.content is too big.

► Elements can be positioned using the top, bottom, Elements can be positioned using the top, bottom, left, and right properties. However, these properties left, and right properties. However, these properties will not work unless the position property is set first. will not work unless the position property is set first.

► They also work differently depending on the They also work differently depending on the positioning method.positioning method.

► There are four different positioning methods.There are four different positioning methods.

Source: Source: http://www.w3schools.com/Css/css_positioning.asphttp://www.w3schools.com/Css/css_positioning.asp

Page 24: Advanced Cascading Style Sheets

Lesson 3: Lesson 3: CSS PositioningCSS Positioning► Static PositioningStatic Positioning► HTML elements are positioned static by default. A static positioned element HTML elements are positioned static by default. A static positioned element

is always positioned according to the normal flow of the page.is always positioned according to the normal flow of the page.► Static positioned elements are not affected by the top, bottom, left, and right Static positioned elements are not affected by the top, bottom, left, and right

properties.properties.

► Fixed PositioningFixed Positioning► An element with fixed position is positioned relative to the browser window.An element with fixed position is positioned relative to the browser window.► It will not move even if the window is scrolled:It will not move even if the window is scrolled:► ExampleExample► p.pos_fixedp.pos_fixed

{{position:fixed;position:fixed;top:30px;top:30px;right:5px;right:5px;}}

► Note:Note: Internet Explorer supports the fixed value only if a !DOCTYPE is Internet Explorer supports the fixed value only if a !DOCTYPE is specified.specified.

► Fixed positioned elements are removed from the normal flow. The document Fixed positioned elements are removed from the normal flow. The document and other elements behave like the fixed positioned element does not exist.and other elements behave like the fixed positioned element does not exist.

► Fixed positioned elements can overlap other elements.Fixed positioned elements can overlap other elements.Source: Source: http://www.w3schools.com/Css/css_positioning.asphttp://www.w3schools.com/Css/css_positioning.asp

Page 25: Advanced Cascading Style Sheets

SPECIAL PAUSE FOR SPECIAL PAUSE FOR DOCTYPE!DOCTYPE!

► Since we were on the topic of browser Since we were on the topic of browser compatibility this is a good spot to stop and compatibility this is a good spot to stop and talk about DOCTYPEtalk about DOCTYPE

► DOCTYPE = Document Type Definition DOCTYPE = Document Type Definition (abbreviation DTD)(abbreviation DTD)

► Every single HTML page should have a Every single HTML page should have a DOCTYPE to be valid for HTML (or XHTML)DOCTYPE to be valid for HTML (or XHTML)

► For Example:For Example:<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN” <!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN”

“http://www.w3.org/TR/html4/strict.dtd”>“http://www.w3.org/TR/html4/strict.dtd”>

Page 26: Advanced Cascading Style Sheets

SPECIAL PAUSE FOR SPECIAL PAUSE FOR DOCTYPE!DOCTYPE!

► DOCTYPE is important because it sets rules that DOCTYPE is important because it sets rules that the HTML document should follow to be correct. the HTML document should follow to be correct.

► For example what version of HTML the author is For example what version of HTML the author is using, the rendering mode to use when using, the rendering mode to use when rendering each HTML document. rendering each HTML document.

► If you do not define DOCTYPE the browsers will If you do not define DOCTYPE the browsers will handle and render the document anyway.handle and render the document anyway.

► Browsers need to make sense of the all the Browsers need to make sense of the all the strange things that come across the web strange things that come across the web

► Without DOCTYPE the results may not look like Without DOCTYPE the results may not look like what you intended because of something called what you intended because of something called DOCTYPE sniffingDOCTYPE sniffing or or DOCTYPE switchingDOCTYPE switching..

Page 27: Advanced Cascading Style Sheets

SPECIAL PAUSE FOR SPECIAL PAUSE FOR DOCTYPE!DOCTYPE!

►A list of DOCTYPES can be found at A list of DOCTYPES can be found at http://www.w3.org/QA/2002/04/valid-http://www.w3.org/QA/2002/04/valid-dtd-list.htmldtd-list.html

►You can test whether your HTML You can test whether your HTML document is following the rules document is following the rules outlined correctly by going to outlined correctly by going to http://validator.w3.org/http://validator.w3.org/

Page 28: Advanced Cascading Style Sheets

Lesson 3: Lesson 3: CSS PositioningCSS Positioning► Relative PositioningRelative Positioning► A relative positioned element is positioned relative to its normal position.A relative positioned element is positioned relative to its normal position.ExampleExampleh2.pos_lefth2.pos_left

{{position:relative;position:relative;left:-20px;left:-20px;}}h2.pos_righth2.pos_right{{position:relative;position:relative;left:20px;left:20px;}}

Try it yourself »Try it yourself » The content of relatively positioned elements can be moved and The content of relatively positioned elements can be moved and overlap other elements, but the reserved space for the element is still overlap other elements, but the reserved space for the element is still preserved in the normal flow.preserved in the normal flow.

ExampleExampleh2.pos_toph2.pos_top

{{position:relative;position:relative;top:-50px;top:-50px;}}

Try it yourself »Try it yourself » Relatively positioned elements are often used as container blocks Relatively positioned elements are often used as container blocks for absolutely positioned elements.for absolutely positioned elements.

Source: Source: http://www.w3schools.com/Css/css_positioning.asphttp://www.w3schools.com/Css/css_positioning.asp

Page 29: Advanced Cascading Style Sheets

Lesson 3: Lesson 3: CSS PositioningCSS Positioning► Absolute PositioningAbsolute Positioning► An absolute position element is positioned relative An absolute position element is positioned relative

to the first parent element that has a position other to the first parent element that has a position other than static. If no such element is found, the than static. If no such element is found, the containing block is <html>:containing block is <html>:

► ExampleExample► h2h2

{{position:absolute;position:absolute;left:100px;left:100px;top:150px;top:150px;}}Try it yourself »Try it yourself » Absolutely positioned elements are Absolutely positioned elements are removed from the normal flow. The document and removed from the normal flow. The document and other elements behave like the absolutely other elements behave like the absolutely positioned element does not exist.positioned element does not exist.

► Absolutely positioned elements can overlap other Absolutely positioned elements can overlap other elements.elements.Source: Source: http://www.w3schools.com/Css/css_positioning.asp

Page 30: Advanced Cascading Style Sheets

Lesson 3: Lesson 3: CSS PositioningCSS Positioning► Overlapping ElementsOverlapping Elements► When elements are positioned outside the normal flow, they can When elements are positioned outside the normal flow, they can

overlap other elements.overlap other elements.► The z-index property specifies the stack order of an element The z-index property specifies the stack order of an element

(which element should be placed in front of, or behind, the (which element should be placed in front of, or behind, the others).others).

► An element can have a positive or negative stack order:An element can have a positive or negative stack order:► ExampleExample► imgimg

{{position:absolute;position:absolute;left:0px;left:0px;top:0px;top:0px;z-index:-1z-index:-1}}Try it yourself »Try it yourself » An element with greater stack order is always in An element with greater stack order is always in front of an element with a lower stack order.front of an element with a lower stack order.

► Note:Note: If two positioned elements overlap, without a z-index If two positioned elements overlap, without a z-index specified, the element positioned last in the HTML code will be specified, the element positioned last in the HTML code will be shown on top.shown on top.Source: Source: http://www.w3schools.com/Css/css_positioning.asp

Page 31: Advanced Cascading Style Sheets

Lesson 3 Assignment:Lesson 3 Assignment:CSS PositioningCSS Positioning

► Open A New Notepad DocumentOpen A New Notepad Document► Create an external CSS style sheet & a HTML Document Create an external CSS style sheet & a HTML Document with 4 div tags with 4 div tags

ininHTML and 4 different styles in the external CSS that demonstrate CSS HTML and 4 different styles in the external CSS that demonstrate CSS

position. position. See example.See example.

► You can use the examples at the following link as a guide: You can use the examples at the following link as a guide: http://www.w3schools.com/Css/css_positioning.asphttp://www.w3schools.com/Css/css_positioning.asp to create your document. to create your document.

CSS Style Example:div{left:0px;left:0px;top:0px;top:0px;z-index:-1z-index:-1}

HTML Example:<div> This box is positioned relative </div>► Save Your Files as style.css and css-position.html in the same folderSave Your Files as style.css and css-position.html in the same folder

Page 32: Advanced Cascading Style Sheets

Lesson 4: Lesson 4: Aligning Block ElementsAligning Block Elements

Page 33: Advanced Cascading Style Sheets

Lesson 4: Lesson 4: Aligning Block Aligning Block ElementsElements In CSS, several properties are used to align In CSS, several properties are used to align

elements horizontally.elements horizontally. Center Aligning Using the margin PropertyCenter Aligning Using the margin Property Block elements can be aligned by setting the Block elements can be aligned by setting the

left and right margins to "auto".left and right margins to "auto". Note: Note: Using margin:auto will not work in IE 8 Using margin:auto will not work in IE 8

and earlier, and earlier, unless a !DOCTYPE is declared.unless a !DOCTYPE is declared.

Page 34: Advanced Cascading Style Sheets

Lesson 4: Lesson 4: Aligning Block ElementsAligning Block Elements► Setting the left and right marginsSetting the left and right margins to auto specifies that to auto specifies that

they should split the available margin equally. The result is a they should split the available margin equally. The result is a centered element:centered element:

► ExampleExample► .center.center

{{margin-left:auto;margin-left:auto;margin-right:auto;margin-right:auto;width:70%;width:70%;background-color:#b0e0e6;background-color:#b0e0e6;}}Try it yourself »Try it yourself »

► Tip:Tip: Aligning has no effect if the width is 100%. Aligning has no effect if the width is 100%.► Note:Note: In IE 5 there is a margin handling bug for block In IE 5 there is a margin handling bug for block

elements. To make the example above work in IE5, add some elements. To make the example above work in IE5, add some extra code. extra code. Try it yourselfTry it yourself

Source: http://www.w3schools.com/css/css_align.asp

Page 35: Advanced Cascading Style Sheets

Lesson 4: Lesson 4: Aligning Block ElementsAligning Block Elements

► Crossbrowser Compatibility IssuesCrossbrowser Compatibility Issues► When aligning elements like this, it is always a When aligning elements like this, it is always a

good idea to predefine margin and padding for the good idea to predefine margin and padding for the <body> element. This is to avoid visual <body> element. This is to avoid visual differences in different browsers.differences in different browsers.

► There is also another problem with IE when using There is also another problem with IE when using the position property. the position property.

► If a container element (in our case <div If a container element (in our case <div class="container">) has a specified width, and class="container">) has a specified width, and the !DOCTYPE declaration is missing, IE will add a the !DOCTYPE declaration is missing, IE will add a 17px margin on the right side. 17px margin on the right side.

► This seems to be space reserved for a scrollbar. This seems to be space reserved for a scrollbar. ► Always set the !DOCTYPE declaration when using Always set the !DOCTYPE declaration when using

the position property. the position property.

Source: http://www.w3schools.com/css/css_align.asp

Page 36: Advanced Cascading Style Sheets

Lesson 4: Lesson 4: Aligning Block ElementsAligning Block Elements

► ExampleExample► bodybody

{{margin:0;margin:0;padding:0;padding:0;}}.container.container{{position:relative;position:relative;width:100%;width:100%;}}.right.right{{position:absolute;position:absolute;right:0px;right:0px;width:300px;width:300px;background-color:#b0e0e6;background-color:#b0e0e6;}}Try it yourself »Try it yourself »

Source: http://www.w3schools.com/css/css_align.asp

Page 37: Advanced Cascading Style Sheets

Lesson 4: Lesson 4: Aligning Block ElementsAligning Block Elements► Left and Right Aligning Using the float Left and Right Aligning Using the float

PropertyProperty► One method of aligning elements is to use the One method of aligning elements is to use the

float property:float property:► ExampleExample.right.right

{{float:right;float:right;width:300px;width:300px;background-color:#b0e0e6;background-color:#b0e0e6;}}Try it yourself »Try it yourself »

Page 38: Advanced Cascading Style Sheets

Lesson 4: Lesson 4: Aligning Block ElementsAligning Block Elements

► Cross browser Compatibility IssuesCross browser Compatibility Issues► When aligning elements like this, it is always a When aligning elements like this, it is always a

good idea to predefine margin and padding for good idea to predefine margin and padding for the <body> element. the <body> element.

► This is to avoid visual differences in different This is to avoid visual differences in different browsers.browsers.

► There is also another problem with IE when using There is also another problem with IE when using the float property. the float property.

► If the !DOCTYPE declaration is missing, IE will If the !DOCTYPE declaration is missing, IE will add a 17px margin on the right side. add a 17px margin on the right side.

► This seems to be space reserved for a scrollbar. This seems to be space reserved for a scrollbar. ► Always set the !DOCTYPE declaration when using Always set the !DOCTYPE declaration when using

the float propertythe float property

Page 39: Advanced Cascading Style Sheets

Lesson 4: Lesson 4: Aligning Block ElementsAligning Block Elements

► ExampleExamplebodybody

{{margin:0;margin:0;padding:0;padding:0;}}.right.right{{float:right;float:right;width:300px;width:300px;background-color:#b0e0e6;background-color:#b0e0e6;}}Try it yourself »Try it yourself »

Page 40: Advanced Cascading Style Sheets

Lesson 5: Lesson 5: FloatFloat

Page 41: Advanced Cascading Style Sheets

Lesson 5: Lesson 5: FloatFloat

►With CSS float, an element can be With CSS float, an element can be pushed to the left or right, allowing pushed to the left or right, allowing other elements to wrap around it.other elements to wrap around it.

►Float is very often used for images, but Float is very often used for images, but it is also useful when working with it is also useful when working with layouts.layouts.

Source:Source:http://w3schools.com/css/css_float.asphttp://w3schools.com/css/css_float.asp

Page 42: Advanced Cascading Style Sheets

Lesson 5: Lesson 5: How Elements How Elements FloatFloat

► Elements are floated horizontally, this means that an element Elements are floated horizontally, this means that an element can only be floated left or right, not up or down.can only be floated left or right, not up or down.

► A floated element will move as far to the left or right as it can. A floated element will move as far to the left or right as it can. Usually this means all the way to the left or right of the Usually this means all the way to the left or right of the containing element.containing element.

► The elements after the floating element will flow around it.The elements after the floating element will flow around it.► The elements before the floating element will not be affected.The elements before the floating element will not be affected.► If an image is floated to the right, a following text flows If an image is floated to the right, a following text flows

around it, to the left:around it, to the left:► ExampleExampleimgimg

{{float:right;float:right;}}Try it yourself »Try it yourself »

Source:Source:http://w3schools.com/css/css_float.asp

Page 43: Advanced Cascading Style Sheets

Lesson 5: Lesson 5: FloatFloat► Floating Elements Next to Each OtherFloating Elements Next to Each Other► If you place several floating elements after each other, they If you place several floating elements after each other, they

will float next to each other if there is room.will float next to each other if there is room.► Here we have made an image gallery using the float property:Here we have made an image gallery using the float property:► ExampleExample.thumbnail .thumbnail

{{float:left;float:left;width:110px;width:110px;height:90px;height:90px;margin:5px;margin:5px;}}Try it yourself »Try it yourself »

Source:Source:http://w3schools.com/css/css_float.asp

Page 44: Advanced Cascading Style Sheets

Lesson 5: Lesson 5: FloatFloat► Turning off Float - Using ClearTurning off Float - Using Clear► Elements after the floating element will flow around it. To Elements after the floating element will flow around it. To

avoid this, use the clear property.avoid this, use the clear property.► The clear property specifies which sides of an element other The clear property specifies which sides of an element other

floating elements are not allowed.floating elements are not allowed.► Add a text line into the image gallery, using the clear Add a text line into the image gallery, using the clear

property:property:► ExampleExample► .text_line.text_line

{{clear:both;clear:both;}}Try it yourself »Try it yourself »

Source:Source:http://w3schools.com/css/css_float.asp

Page 45: Advanced Cascading Style Sheets

Lesson 5 Assignment:Lesson 5 Assignment:CSS Align and FloatCSS Align and Float

► Open A New Notepad DocumentOpen A New Notepad Document► Create an external CSS style sheet & a HTML Document Create an external CSS style sheet & a HTML Document with 6 div with 6 div

tags intags inHTML and 4 different styles in the external CSS that demonstrate CSS HTML and 4 different styles in the external CSS that demonstrate CSS

align and float. See example.align and float. See example.► You can use the examples at the following link as a guide: You can use the examples at the following link as a guide:

http://www.w3schools.com/Css/css_positioning.asp to create your document.http://www.w3schools.com/Css/css_positioning.asp to create your document.

CSS Style Example:.auto{margin-left:auto;margin-right:auto;background-color:red;width=400px;height:200px;}

HTML Example:<div> This box is floating left</div>► Save Your Files as style.css and css-float.html in the same folderSave Your Files as style.css and css-float.html in the same folder

Page 46: Advanced Cascading Style Sheets

Lesson 6: Lesson 6: ListsLists

Page 47: Advanced Cascading Style Sheets

Lesson 6: Lesson 6: ListsLists

The CSS list properties allow you The CSS list properties allow you to:to:

► Set different list item markers for Set different list item markers for ordered lists ordered lists

► Set different list item markers for Set different list item markers for unordered lists unordered lists

► Set an image as the list item markerSet an image as the list item marker

Source: Source: http://w3schools.com/css/css_list.asphttp://w3schools.com/css/css_list.asp

Page 48: Advanced Cascading Style Sheets

Lesson 6: Lesson 6: ListsLists

In HTML, there are two types of lists:In HTML, there are two types of lists:► unordered lists - the list items are marked unordered lists - the list items are marked

with bullets with bullets ► ordered lists - the list items are marked with ordered lists - the list items are marked with

numbers or lettersnumbers or letters► What is the tag in HTML that sets up an What is the tag in HTML that sets up an

ordered list?ordered list?► What is the tag in HTML that sets up an What is the tag in HTML that sets up an

unordered list? unordered list? ► With CSS, lists can be styled further, and With CSS, lists can be styled further, and

images can be used as the list item marker.images can be used as the list item marker.

Source: Source: http://w3schools.com/css/css_list.asphttp://w3schools.com/css/css_list.asp

Page 49: Advanced Cascading Style Sheets

Lesson 6: Lesson 6: Different List Item Different List Item MarkersMarkers

►The type of list item marker is specified The type of list item marker is specified with the list-style-type property:with the list-style-type property:

►ExampleExample

ul.a {list-style-type: circle;}ul.a {list-style-type: circle;}

ul.b {list-style-type: square;}ul.b {list-style-type: square;}

ol.c {list-style-type: upper-roman;}ol.c {list-style-type: upper-roman;}

ol.d {list-style-type: lower-alpha;}ol.d {list-style-type: lower-alpha;}Try it yourself »Try it yourself »

Source: Source: http://w3schools.com/css/css_list.asphttp://w3schools.com/css/css_list.asp

Page 50: Advanced Cascading Style Sheets

Lesson 6 Assignment:Lesson 6 Assignment:CSS Lists UnorderedCSS Lists Unordered

Create a web page with multiple Create a web page with multiple unorderedunordered CSS list types. CSS list types.

►Values for Unordered ListsValues for Unordered Lists

none = no markernone = no marker

discdisc

circlecircle

squaresquare

Page 51: Advanced Cascading Style Sheets

Lesson 6 Assignment:Lesson 6 Assignment:CSS Lists OrderedCSS Lists Ordered

Create an HTML web page with 2 ordered and 2 unordered CSS list Create an HTML web page with 2 ordered and 2 unordered CSS list types in an external style sheet. See Example.types in an external style sheet. See Example.

Values for Ordered Lists Examples:Values for Ordered Lists Examples:► Armenian = The marker is traditional Armenian numberingArmenian = The marker is traditional Armenian numbering► Decimal = The marker is a number Decimal = The marker is a number ► decimal-leading-zero = The marker is a number padded by decimal-leading-zero = The marker is a number padded by

initial zeros (01, 02, 03, etc.)initial zeros (01, 02, 03, etc.)► Georgian = The marker is traditional Georgian numbering (an, Georgian = The marker is traditional Georgian numbering (an,

ban, gan, etc.)ban, gan, etc.)► lower-alpha = The marker is lower-alpha (a, b, c, d, e, etc.)lower-alpha = The marker is lower-alpha (a, b, c, d, e, etc.)► lower-greek = The marker is lower-greek (alpha, beta, gamma, lower-greek = The marker is lower-greek (alpha, beta, gamma,

etc.)etc.)► lower-latin = The marker is lower-latin (a, b, c, d, e, etc.)lower-latin = The marker is lower-latin (a, b, c, d, e, etc.)► lower-roman = The marker is lower-roman (i, ii, iii, iv, v, etc.)lower-roman = The marker is lower-roman (i, ii, iii, iv, v, etc.)► upper-alpha = The marker is upper-alpha (A, B, C, D, E, etc.) upper-alpha = The marker is upper-alpha (A, B, C, D, E, etc.) ► upper-latin = The marker is upper-latin (A, B, C, D, E, etc.)upper-latin = The marker is upper-latin (A, B, C, D, E, etc.)► upper-roman = The marker is upper-roman (I, II, III, IV, V, etc.)upper-roman = The marker is upper-roman (I, II, III, IV, V, etc.)

Page 52: Advanced Cascading Style Sheets

Lesson 6: Lesson 6: Lists Using ImagesLists Using Images

► An Image as The List Item MarkerAn Image as The List Item Marker► To specify an image as the list item marker, use the list-style-To specify an image as the list item marker, use the list-style-

image property:image property:► ExampleExample► ulul

{{list-style-image: url('sqpurple.gif');list-style-image: url('sqpurple.gif');}}

► Try it yourself »Try it yourself » ► The example above does not display equally in all browsers. The example above does not display equally in all browsers.

IE and Opera will display the image-marker a little bit higher IE and Opera will display the image-marker a little bit higher than Firefox, Chrome, and Safari.than Firefox, Chrome, and Safari.

More list examples: More list examples: http://w3schools.com/css/tryit.asp?filename=http://w3schools.com/css/tryit.asp?filename=trycss_list-style-type_alltrycss_list-style-type_all

Page 53: Advanced Cascading Style Sheets

Lesson 6 Assignment:Lesson 6 Assignment:CSS Lists With An ImageCSS Lists With An Image

► Open your css-lists.html web page in Open your css-lists.html web page in notepadnotepad

► add 2 list types in the external style add 2 list types in the external style

sheet that have pictures as bullets. sheet that have pictures as bullets.

► See Example.See Example.

► You can download a royalty free picture You can download a royalty free picture from from use as a bullet.use as a bullet.

Page 54: Advanced Cascading Style Sheets

Lesson 7: Lesson 7: Fonts & Text On Web Fonts & Text On Web

PagesPages

Page 55: Advanced Cascading Style Sheets

Lesson 7: Lesson 7: Points are For Points are For PrintPrintMany Web designers have gotten into the bad Many Web designers have gotten into the bad

habit of using point sizes to define their font sizes habit of using point sizes to define their font sizes on the screen. on the screen.

But points are a print unit of measure, and the But points are a print unit of measure, and the Web is usually viewed on the screen. Web is usually viewed on the screen.

This means that when you specify 14-point type, it This means that when you specify 14-point type, it might display much larger or smaller than you might display much larger or smaller than you expect. expect.

The most common place this is noticed is between The most common place this is noticed is between Macintosh and Windows. Macintosh typically Macintosh and Windows. Macintosh typically displays things almost 25% smaller than the same displays things almost 25% smaller than the same page on Windows. page on Windows.

The next few slides will explain how to adjust The next few slides will explain how to adjust fonts to work well on web pages.fonts to work well on web pages.

Page 56: Advanced Cascading Style Sheets

Lesson 7: Lesson 7: Setting Font SizeSetting Font Size

Font SizeFont Size►The font-size property sets the size of the text.The font-size property sets the size of the text.

►Being able to manage the text size is important in Being able to manage the text size is important in web design. However, you should not use font size web design. However, you should not use font size adjustments to make paragraphs look like headings, adjustments to make paragraphs look like headings, or headings look like paragraphs.or headings look like paragraphs.

►Always use the proper HTML tags, like <h1> - Always use the proper HTML tags, like <h1> - <h6> for headings and <p> for paragraphs.<h6> for headings and <p> for paragraphs.

►The font-size value can be an absolute, or relative The font-size value can be an absolute, or relative size.size.

Page 57: Advanced Cascading Style Sheets

►Absolute size:Absolute size:►Sets the text to a specified size Sets the text to a specified size ►Does not allow a user to change Does not allow a user to change

the text size in all browsers (bad the text size in all browsers (bad for accessibility reasons) for accessibility reasons)

►Absolute size is useful when the Absolute size is useful when the physical size of the output is physical size of the output is knownknown

Lesson 7: Lesson 7: Setting Font SizeSetting Font Size

Page 58: Advanced Cascading Style Sheets

►Relative size:Relative size:►Sets the size relative to surrounding Sets the size relative to surrounding

elements elements ►Allows a user to change the text Allows a user to change the text

size in browserssize in browsers► If you do not specify a font size, If you do not specify a font size,

the default size for normal text, like the default size for normal text, like paragraphs, is 16px (16px=1em).paragraphs, is 16px (16px=1em).

Lesson 7: Lesson 7: Setting Font SizeSetting Font Size

Page 59: Advanced Cascading Style Sheets

Lesson 7: Lesson 7: Setting Font Size with Setting Font Size with PixelsPixels

►Set Font Size With PixelsSet Font Size With Pixels►Setting the text size with pixels, gives Setting the text size with pixels, gives

you full control over the text size:you full control over the text size:►ExampleExample

h1 {font-size:40px;}h1 {font-size:40px;}

h2 {font-size:30px;}h2 {font-size:30px;}

p {font-size:14px;}p {font-size:14px;}Try it yourself »Try it yourself »

Browser Compatibility: This example allows Firefox, Chrome, and Safari to resize the text, but not Internet Explorer.The text can be resized in all browsers using the zoom tool (however, this resizes the entire page, not just the text).

Page 60: Advanced Cascading Style Sheets

Lesson 7: Lesson 7: Setting Font Size with EmSetting Font Size with Em► Set Font Size With EmSet Font Size With Em► To avoid the resizing problem with Internet Explorer, many To avoid the resizing problem with Internet Explorer, many

developers use em instead of pixels.developers use em instead of pixels.► The em size unit is recommended by the W3C.The em size unit is recommended by the W3C.► 1em is equal to the current font size. The default text size in 1em is equal to the current font size. The default text size in

browsers is 16px. So, the default size of 1em is 16px.browsers is 16px. So, the default size of 1em is 16px.► The size can be calculated from pixels to em using this formula: The size can be calculated from pixels to em using this formula:

pixelspixels/16=/16=emem

► ExampleExampleh1 {font-size:2.5em;} /* 40px/16=2.5em */h1 {font-size:2.5em;} /* 40px/16=2.5em */h2 {font-size:1.875em;} /* 30px/16=1.875em */h2 {font-size:1.875em;} /* 30px/16=1.875em */p {font-size:0.875em;} /* 14px/16=0.875em */p {font-size:0.875em;} /* 14px/16=0.875em */

Try it yourself »Try it yourself »

► In the example above, the text size in em is the same as the previous In the example above, the text size in em is the same as the previous example in pixels. However, with the em size, it is possible to adjust example in pixels. However, with the em size, it is possible to adjust the text size in all browsers. the text size in all browsers.

► Unfortunately, there is still a problem with IE. When resizing the text, Unfortunately, there is still a problem with IE. When resizing the text, it becomes larger than it should when made larger, and smaller than it becomes larger than it should when made larger, and smaller than it should when made smaller.it should when made smaller.

Page 61: Advanced Cascading Style Sheets

Lesson 7: Lesson 7: Setting Font Size with EmSetting Font Size with Em

► Use a Combination of Percent and EmUse a Combination of Percent and Em► The solution that works in all browsers, is to set a The solution that works in all browsers, is to set a

default font-size in percent for the body element:default font-size in percent for the body element:► ExampleExample► body {font-size:100%;}body {font-size:100%;}

h1 {font-size:2.5em;}h1 {font-size:2.5em;}h2 {font-size:1.875em;}h2 {font-size:1.875em;}p {font-size:0.875em;}p {font-size:0.875em;}

► Try it yourself »Try it yourself » ► Our code now works great! It shows the same text Our code now works great! It shows the same text

size in all browsers, and allows all browsers to zoom size in all browsers, and allows all browsers to zoom or resize the text!or resize the text!

Page 62: Advanced Cascading Style Sheets

Lesson 7: Lesson 7: FontFont StyleStyle►The font-style property is mostly used to specify The font-style property is mostly used to specify italic text.italic text.►This property has three values:This property has three values: normal - The text is shown normally normal - The text is shown normally italic - The text is shown in italics italic - The text is shown in italics oblique - The text is "leaning" (oblique is very similar to oblique - The text is "leaning" (oblique is very similar to

italic, but less supported)italic, but less supported)

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

h1 {font-style: italic}h1 {font-style: italic}h2 {font-style: normal}h2 {font-style: normal}p {font-style: oblique}p {font-style: oblique}Try it yourself »Try it yourself »

Page 63: Advanced Cascading Style Sheets

Lesson 7: Lesson 7: CSS Font FamiliesCSS Font Families► In CSS, there are two types of font family names:In CSS, there are two types of font family names:► generic familygeneric family - a group of font families with a similar - a group of font families with a similar

look (like "Serif" or "Monospace") look (like "Serif" or "Monospace") ► font familyfont family - a specific font family (like "Times New - a specific font family (like "Times New

Roman" or "Arial")Roman" or "Arial")

► Generic family Generic family Serif (Times New Roman, Georgia) Serif fonts have small lines at Serif (Times New Roman, Georgia) Serif fonts have small lines at

the ends on some charactersthe ends on some characters Sans-serif (Arial, Verdana) "Sans" means without - these fonts do Sans-serif (Arial, Verdana) "Sans" means without - these fonts do

not have the lines at the ends of charactersnot have the lines at the ends of characters Monospace (Courier, New Lucida, Console) All monospace Monospace (Courier, New Lucida, Console) All monospace

characters have the same widthcharacters have the same width

Page 64: Advanced Cascading Style Sheets

Lesson 7: Lesson 7: CSS Font FamiliesCSS Font Families► The font family of a text is set with the font-family property.The font family of a text is set with the font-family property.► The font-family property should hold several font names as a The font-family property should hold several font names as a

"fallback" system. If the browser does not support the first "fallback" system. If the browser does not support the first font, it tries the next font.font, it tries the next font.

► Start with the font you want, and end with a generic family, to Start with the font you want, and end with a generic family, to let the browser pick a similar font in the generic family, if no let the browser pick a similar font in the generic family, if no other fonts are available. other fonts are available.

NoteNote: If the name of a font family is more than one word, it must : If the name of a font family is more than one word, it must be in quotation marks, like font-family: "Times New Roman".be in quotation marks, like font-family: "Times New Roman".

More than one font familyMore than one font family is specified in a comma-separated is specified in a comma-separated listlist

► ExampleExample p{font-family:"Times New Roman", Times, serif;} p{font-family:"Times New Roman", Times, serif;}

Try it yourself »Try it yourself »

Page 65: Advanced Cascading Style Sheets

Lesson 7: Lesson 7: Font BoldFont Bold

Examples to specify bold by Examples to specify bold by thickness:thickness:

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

Page 66: Advanced Cascading Style Sheets

Lesson 7: Lesson 7: Setting all the Setting all the Styles in Styles in

one line for FONTone line for FONTShortcut Example:Shortcut Example:pp{{font: italic small-caps 900 12px font: italic small-caps 900 12px

arialarial}}

Page 67: Advanced Cascading Style Sheets

Lesson 7: Lesson 7: Text ColorText Color► The color property is used to set the color of the text. The The color property is used to set the color of the text. The

color can be specified by:color can be specified by: name - a color name, like "red" name - a color name, like "red" RGB - an RGB value, like "rgb(255,0,0)" RGB - an RGB value, like "rgb(255,0,0)" Hex - a hex value, like "#ff0000"Hex - a hex value, like "#ff0000"

► The default color for a page is defined in the body selector.The default color for a page is defined in the body selector.

ExampleExample► body {color:blue;}body {color:blue;}

h1 {color:#00ff00;}h1 {color:#00ff00;}h2 {color:rgb(255,0,0);}h2 {color:rgb(255,0,0);}Try it yourself »Try it yourself »

► For W3C compliant CSS: If you define the color property, For W3C compliant CSS: If you define the color property,

you must also define the background-color property. you must also define the background-color property.

Page 68: Advanced Cascading Style Sheets

Lesson 7: Lesson 7: Text AlignmentText Alignment► The text-align property is used to set the horizontal The text-align property is used to set the horizontal

alignment of a text.alignment of a text.

► Text can be centered, or aligned to the left or right, or Text can be centered, or aligned to the left or right, or justified.justified.

► When text-align is set to "justify", each line is stretched so When text-align is set to "justify", each line is stretched so that every line has equal width, and the left and right that every line has equal width, and the left and right margins are straight (like in magazines and newspapers).margins are straight (like in magazines and newspapers).

► ExampleExampleh1 {text-align:center;}h1 {text-align:center;}p.date {text-align:right;}p.date {text-align:right;}p.main {text-align:justify;} p.main {text-align:justify;}

Try it yourself »Try it yourself »

Page 69: Advanced Cascading Style Sheets

Lesson 7: Lesson 7: Text DecorationText Decoration► The text-decoration property is used to set or remove decorations from The text-decoration property is used to set or remove decorations from

text.text.► The text-decoration property is mostly used to remove underlines from The text-decoration property is mostly used to remove underlines from

links for design purposeslinks for design purposes

► ExampleExamplea {text-decoration:none;} a {text-decoration:none;}

Try it yourself »Try it yourself » It can also be used to decorate textIt can also be used to decorate text

► ExampleExampleh1 {text-decoration:overline;}h1 {text-decoration:overline;}h2 {text-decoration:line-through;}h2 {text-decoration:line-through;}h3 {text-decoration:underline;}h3 {text-decoration:underline;}h4 {text-decoration:blink;}h4 {text-decoration:blink;}

Try it yourself »Try it yourself » It is not recommended to underline text that is not a link, as this often It is not recommended to underline text that is not a link, as this often

confuses users.confuses users.

Page 70: Advanced Cascading Style Sheets

Lesson 7: Lesson 7: Text TransformationText Transformation

► The text-transform property is used to specify The text-transform property is used to specify uppercase and lowercase letters in a text.uppercase and lowercase letters in a text.

► It can be used to turn everything into uppercase It can be used to turn everything into uppercase or lowercase letters, or capitalize the first letter of or lowercase letters, or capitalize the first letter of each word.each word.

► ExampleExamplep.uppercase {text-transform:uppercase;}p.uppercase {text-transform:uppercase;}p.lowercase {text-transform:lowercase;}p.lowercase {text-transform:lowercase;}p.capitalize {text-transform:capitalize;}p.capitalize {text-transform:capitalize;}

Try it yourself »Try it yourself »

Page 71: Advanced Cascading Style Sheets

Lesson 7: Lesson 7: Text IndentationText Indentation

►The text-indentation property is used The text-indentation property is used to specify the indentation of the first to specify the indentation of the first line of a text.line of a text.

►ExampleExample

p {text-indent:50px;}p {text-indent:50px;}Try it yourself »Try it yourself »

Page 72: Advanced Cascading Style Sheets

Lesson 7 Assignment:Lesson 7 Assignment:CSS Fonts & TextCSS Fonts & Text

► Create a new external notepad CSS style Create a new external notepad CSS style sheet and an HTML document that shows sheet and an HTML document that shows 10 paragraphs with different examples of 10 paragraphs with different examples of formatting text. formatting text.

► Save Your File as css-fonts.html and your Save Your File as css-fonts.html and your style sheet into your folder.style sheet into your folder.

Page 73: Advanced Cascading Style Sheets

Lesson 8: Lesson 8: CSS TablesCSS Tables

Page 74: Advanced Cascading Style Sheets

Lesson 8: Lesson 8: HTML Tables ReviewHTML Tables Review

►Tables are defined with the <table> Tables are defined with the <table> tag.tag.

►A table is divided into rows (with the A table is divided into rows (with the <tr> tag), <tr> tag), each row is divided into data cells (with each row is divided into data cells (with

the <td> tag). the <td> tag). ►td stands for "table data," and holds td stands for "table data," and holds

the content of a data cell. the content of a data cell. A <td> tag can contain text, links, A <td> tag can contain text, links,

images, lists, forms, other tables, etc.images, lists, forms, other tables, etc.

Page 75: Advanced Cascading Style Sheets

Lesson 8: Lesson 8: HTML Tables ReviewHTML Tables Review

Table ExampleTable Example<table border="1"><table border="1">

<tr><tr><td>row 1, cell 1</td><td>row 1, cell 1</td><td>row 1, cell 2</td><td>row 1, cell 2</td></tr></tr><tr><tr><td>row 2, cell 1</td><td>row 2, cell 1</td><td>row 2, cell 2</td><td>row 2, cell 2</td></tr></tr></table> </table>

Page 76: Advanced Cascading Style Sheets

Lesson 8: Lesson 8: CSS Table BordersCSS Table Borders

► The look of an HTML table can be greatly improved The look of an HTML table can be greatly improved with CSSwith CSS

Table BordersTable Borders► To specify table borders in CSS, use the border To specify table borders in CSS, use the border

property.property.► The example below specifies a black border for table, The example below specifies a black border for table,

th, and td elements:th, and td elements:► ExampleExampletable, th, tdtable, th, td

{{border: 1px solid black;border: 1px solid black;}}Try it yourself »Try it yourself »

Page 77: Advanced Cascading Style Sheets

Lesson 8: Lesson 8: Table Width and HeightTable Width and Height

► Width and height of a table is defined by the width Width and height of a table is defined by the width and height properties.and height properties.

► The example below sets the width of the table to The example below sets the width of the table to 100%, and the height of the th elements to 50px:100%, and the height of the th elements to 50px:

► ExampleExample► table table

{{width:100%;width:100%;}}thth{{height:50px;height:50px;} } Try it yourself »Try it yourself »

Page 78: Advanced Cascading Style Sheets

Lesson 8: Lesson 8: Table Text AlignmentTable Text Alignment

► The text in a table is aligned with the text-align and vertical-align The text in a table is aligned with the text-align and vertical-align properties.properties.

► The text-align property sets the horizontal alignment, like left, right, The text-align property sets the horizontal alignment, like left, right, or center:or center:

► ExampleExample► tdtd

{{text-align:right;text-align:right;}}Try it yourself »Try it yourself » The vertical-align property sets the vertical The vertical-align property sets the vertical alignment, like top, bottom, or middle:alignment, like top, bottom, or middle:

► ExampleExample► tdtd

{{height:50px;height:50px;vertical-align:bottom;vertical-align:bottom;}}Try it yourself »Try it yourself »

Page 79: Advanced Cascading Style Sheets

Lesson 8: Lesson 8: Table PaddingTable Padding

►To control the space between the To control the space between the border and content in a table, use the border and content in a table, use the padding property on td and th padding property on td and th elements:elements:

►ExampleExample►tdtd

{{padding:15px;padding:15px;}}Try it yourself »Try it yourself »

Page 80: Advanced Cascading Style Sheets

Lesson 8: Lesson 8: Table ColorTable Color

► The example below specifies the color of the The example below specifies the color of the borders, and the text and background color of th borders, and the text and background color of th elements:elements:

► ExampleExample► table, td, thtable, td, th

{{border:1px solid green;border:1px solid green;}}thth{{background-color:green;background-color:green;color:white;color:white;}}Try it yourself »Try it yourself »

Page 81: Advanced Cascading Style Sheets

Lesson 8 Assignment:Lesson 8 Assignment:CSS TableCSS Table

► Create a new external notepad CSS style Create a new external notepad CSS style sheet and an HTML document that shows sheet and an HTML document that shows a table with 5 rows and 3 columns with a table with 5 rows and 3 columns with different examples of formatting text different examples of formatting text inside of it. inside of it.

► Save Your File as css-table.html and your Save Your File as css-table.html and your style sheet into your folder.style sheet into your folder.

Page 82: Advanced Cascading Style Sheets

Lesson 9: Lesson 9:

White Space & White Space & BordersBorders

Page 83: Advanced Cascading Style Sheets

Lesson 9: Lesson 9: White SpaceWhite Space

► In web pages white space will allow you to define In web pages white space will allow you to define the look and feel of a web page by providing the look and feel of a web page by providing white area around elements.white area around elements.

► Let’s take a look at some pages that make good Let’s take a look at some pages that make good use of white space. use of white space.

► http://online.wsj.com/home-pagehttp://online.wsj.com/home-page► http://www.csszengarden.com/?cssfile=/http://www.csszengarden.com/?cssfile=/

206/206.css&page=0206/206.css&page=0► http://www.csszengarden.com/?cssfile=/http://www.csszengarden.com/?cssfile=/

210/210.css&page=0210/210.css&page=0

Page 84: Advanced Cascading Style Sheets

Lesson 9: Lesson 9: BordersBorders

► CSS Border PropertiesCSS Border Properties► The CSS border properties allow you to The CSS border properties allow you to

specify the style and color of an element's specify the style and color of an element's border.border.

► Border StyleBorder Style► The border-style property specifies what kind The border-style property specifies what kind

of border to display.of border to display.► None of the border properties will have ANY None of the border properties will have ANY

effect unless the effect unless the border-styleborder-style property is property is set!set!

Page 85: Advanced Cascading Style Sheets

Lesson 9: Lesson 9: Border-style values:Border-style values:

none: Defines no bordernone: Defines no border dotted: Defines a dotted borderdotted: Defines a dotted border dashed: Defines a dashed borderdashed: Defines a dashed border solid: Defines a solid bordersolid: Defines a solid border double: Defines two borders. The width of the two borders double: Defines two borders. The width of the two borders

are the same as the border-width valueare the same as the border-width value groove: Defines a 3D grooved border. The effect depends groove: Defines a 3D grooved border. The effect depends

on the border-color valueon the border-color value ridge: Defines a 3D ridged border. The effect depends on ridge: Defines a 3D ridged border. The effect depends on

the border-color valuethe border-color value inset: Defines a 3D inset border. The effect depends on the inset: Defines a 3D inset border. The effect depends on the

border-color valueborder-color value outset: Defines a 3D outset border. The effect depends on outset: Defines a 3D outset border. The effect depends on

the border-color valuethe border-color value

Page 86: Advanced Cascading Style Sheets

Lesson 9: Lesson 9: Border WidthBorder Width

► The border-width property is used to set the width of the The border-width property is used to set the width of the border.border.

► The width is set in pixels, or by using one of the three pre-The width is set in pixels, or by using one of the three pre-defined values: thin, medium, or thick.defined values: thin, medium, or thick.

► Note:Note: The "border-width" property does not work if it is used The "border-width" property does not work if it is used alone. Use the "border-style" property to set the borders first.alone. Use the "border-style" property to set the borders first.

► ExampleExample► p.onep.one

{{border-style:solid;border-style:solid;border-width:5px;border-width:5px;}}p.twop.two{{border-style:solid;border-style:solid;border-width:medium;border-width:medium;} } Try it yourself »Try it yourself »

Page 87: Advanced Cascading Style Sheets

Lesson 9: Lesson 9: Border ColorBorder Color

► The border-color property is used to set the color of the border. The color can The border-color property is used to set the color of the border. The color can be set by:be set by:

► name - specify a color name, like "red" name - specify a color name, like "red" ► RGB - specify a RGB value, like "rgb(255,0,0)" RGB - specify a RGB value, like "rgb(255,0,0)" ► Hex - specify a hex value, like "#ff0000"Hex - specify a hex value, like "#ff0000"► You can also set the border color to "transparent".You can also set the border color to "transparent".► Note:Note: The "border-color" property does not work if it is used alone. Use the The "border-color" property does not work if it is used alone. Use the

"border-style" property to set the borders first."border-style" property to set the borders first.► ExampleExample► p.onep.one

{{border-style:solid;border-style:solid;border-color:red;border-color:red;}}p.twop.two{{border-style:solid;border-style:solid;border-color:#98bf21;border-color:#98bf21;} } Try it yourself »Try it yourself »

Page 88: Advanced Cascading Style Sheets

Lesson 9: Lesson 9: Border - Individual sidesBorder - Individual sides

► In CSS it is possible to specify different borders for different In CSS it is possible to specify different borders for different sidessides

► ExampleExamplepp

{{border-top-style:dotted;border-top-style:dotted;border-right-style:solid;border-right-style:solid;border-bottom-style:dotted;border-bottom-style:dotted;border-left-style:solid;border-left-style:solid;}}Try it yourself »Try it yourself »

► The example above can also be set with a single propertyThe example above can also be set with a single property► ExampleExampleborder-style:dotted solid;border-style:dotted solid;

Try it yourself »Try it yourself »

Page 89: Advanced Cascading Style Sheets

Lesson 9: Lesson 9: Border - Shorthand propertyBorder - Shorthand property

► As you can see from the examples above, there are many As you can see from the examples above, there are many properties to consider when dealing with borders.properties to consider when dealing with borders.

► To shorten the code, it is also possible to specify all the border To shorten the code, it is also possible to specify all the border properties in one property. This is called a shorthand property.properties in one property. This is called a shorthand property.

► The shorthand property for the border properties is "border":The shorthand property for the border properties is "border":► ExampleExample► border:5px solid red;border:5px solid red;

Try it yourself »Try it yourself »

► When using the border property, the order of the values are:When using the border property, the order of the values are:► border-width border-width ► border-style border-style ► border-colorborder-color

► It does not matter if one of the values above are missing (although, It does not matter if one of the values above are missing (although, border-style is required), as long as the rest are in the specified border-style is required), as long as the rest are in the specified order.order.

Page 90: Advanced Cascading Style Sheets

Lesson 9: Lesson 9: White Space - MarginsWhite Space - Margins

► The CSS margin properties define the space (white space) The CSS margin properties define the space (white space) around elements.around elements.

► The margin clears an area around an element (outside the The margin clears an area around an element (outside the border).border).

► The margin does not have a background color, and is The margin does not have a background color, and is completely transparent.completely transparent.

► The top, right, bottom, and left margin can be changed The top, right, bottom, and left margin can be changed independently using separate properties. independently using separate properties.

► A shorthand margin property can also be used, to change all A shorthand margin property can also be used, to change all margins at once.margins at once.

► Possible ValuesPossible Values Auto - The browser sets the margin.Auto - The browser sets the margin.

The result of this is dependant of the browserThe result of this is dependant of the browser Length - Length - Defines a fixed margin (in pixels, pt, em, etc.) Defines a fixed margin (in pixels, pt, em, etc.) % - % - Defines a margin in % of the containing element. It is Defines a margin in % of the containing element. It is

possible to use negative values, to overlap content.possible to use negative values, to overlap content.

Page 91: Advanced Cascading Style Sheets

Lesson 9: Lesson 9: White Space - MarginsWhite Space - Margins

► The margin property can have from one to four values.The margin property can have from one to four values.► margin:25px 50px 75px 100px; margin:25px 50px 75px 100px;

top margin is 25px top margin is 25px right margin is 50px right margin is 50px bottom margin is 75px bottom margin is 75px left margin is 100pxleft margin is 100px

► margin:25px 50px 75px;margin:25px 50px 75px; top margin is 25px top margin is 25px right and left margins are 50px right and left margins are 50px bottom margin is 75pxbottom margin is 75px

► margin:25px 50px;margin:25px 50px; top and bottom margins are 25px top and bottom margins are 25px right and left margins are 50pxright and left margins are 50px

► margin:25px;margin:25px; all four margins are 25pxall four margins are 25px

Page 92: Advanced Cascading Style Sheets

Lesson 9: Lesson 9: White Space - White Space - MarginsMargins

►Margin - Shorthand propertyMargin - Shorthand property►To shorten the code, it is possible to To shorten the code, it is possible to

specify all the margin properties in one specify all the margin properties in one property. This is called a shorthand property. This is called a shorthand property.property.

►The shorthand property for all the margin The shorthand property for all the margin properties is "margin":properties is "margin":

►ExampleExample►margin:100px 50px;margin:100px 50px;

Try it yourself »Try it yourself »

Page 93: Advanced Cascading Style Sheets

Lesson 9: Lesson 9: White Space - MarginsWhite Space - Margins

►Margin - Individual sidesMargin - Individual sides► In CSS, it is possible to specify In CSS, it is possible to specify

different margins for different sides:different margins for different sides:►ExampleExamplemargin-top:100px;margin-top:100px;

margin-bottom:100px;margin-bottom:100px;margin-right:50px;margin-right:50px;margin-left:50px;margin-left:50px;Try it yourself »Try it yourself »

Page 94: Advanced Cascading Style Sheets

Lesson 9: Lesson 9: White Space - PaddingWhite Space - Padding

► The CSS padding properties define the space between The CSS padding properties define the space between the element border and the element content.the element border and the element content.

► The padding clears an area around the content (inside The padding clears an area around the content (inside the border) of an element. the border) of an element.

► The padding is affected by the background color of the The padding is affected by the background color of the element.element.

► The top, right, bottom, and left padding can be The top, right, bottom, and left padding can be changed independently using separate properties. changed independently using separate properties.

► A shorthand padding property can also be used, to A shorthand padding property can also be used, to change all paddings at once.change all paddings at once.

► Possible ValuesPossible Values► Length - Length - Defines a fixed padding (in pixels, pt, em, etc.)Defines a fixed padding (in pixels, pt, em, etc.)► % - % - Defines a padding in % of the containing elementDefines a padding in % of the containing element

Page 95: Advanced Cascading Style Sheets

Lesson 9: Lesson 9: White Space - PaddingWhite Space - Padding

►Padding - Individual sidesPadding - Individual sides► In CSS, it is possible to specify In CSS, it is possible to specify

different padding for different sides:different padding for different sides:►ExampleExample►padding-top:25px;padding-top:25px;

padding-bottom:25px;padding-bottom:25px;padding-right:50px;padding-right:50px;padding-left:50px;padding-left:50px;Try it yourself »Try it yourself »

Page 96: Advanced Cascading Style Sheets

Lesson 9: Lesson 9: White Space - PaddingWhite Space - Padding

►Padding - Shorthand propertyPadding - Shorthand property►To shorten the code, it is possible to To shorten the code, it is possible to

specify all the padding properties in specify all the padding properties in one property. This is called a one property. This is called a shorthand property.shorthand property.

►The shorthand property for all the The shorthand property for all the padding properties is "padding":padding properties is "padding":

Page 97: Advanced Cascading Style Sheets

Lesson 9: Lesson 9: White Space - PaddingWhite Space - Padding

►Padding - Individual sidesPadding - Individual sides► In CSS, it is possible to specify In CSS, it is possible to specify

different padding for different sides:different padding for different sides:►ExampleExample►padding-top:25px;padding-top:25px;

padding-bottom:25px;padding-bottom:25px;padding-right:50px;padding-right:50px;padding-left:50px;padding-left:50px;Try it yourself »Try it yourself »

Page 98: Advanced Cascading Style Sheets

Lesson 9: Lesson 9: White Space - PaddingWhite Space - Padding► The padding property can have from one to four values.The padding property can have from one to four values.► padding:25px 50px 75px 100px; padding:25px 50px 75px 100px;

top padding is 25px top padding is 25px right padding is 50px right padding is 50px bottom padding is 75px bottom padding is 75px left padding is 100pxleft padding is 100px

► padding:25px 50px 75px;padding:25px 50px 75px; top padding is 25px top padding is 25px right and left paddings are 50px right and left paddings are 50px bottom padding is 75pxbottom padding is 75px

► padding:25px 50px;padding:25px 50px; top and bottom paddings are 25px top and bottom paddings are 25px right and left paddings are 50pxright and left paddings are 50px

► padding:25px;padding:25px; all four paddings are 25pxall four paddings are 25px

Page 99: Advanced Cascading Style Sheets

Lesson 9 Assignment:Lesson 9 Assignment:CSS White SpaceCSS White Space

► Create a new external notepad CSS style Create a new external notepad CSS style sheet and an HTML document that shows sheet and an HTML document that shows a 4 div tags with 5 examples of white a 4 div tags with 5 examples of white space. space.

► Save Your File as css-whitespace.html and Save Your File as css-whitespace.html and your style sheet into your folder.your style sheet into your folder.

Page 100: Advanced Cascading Style Sheets

Lesson 10: Lesson 10:

Navigation MenusNavigation Menus

Page 101: Advanced Cascading Style Sheets

Lesson 10: Lesson 10: Navigation MenusNavigation Menus

► Navigation BarsNavigation Bars► Having easy-to-use navigation is important Having easy-to-use navigation is important

for any web site.for any web site.► With CSS you can transform boring HTML With CSS you can transform boring HTML

menus into good-looking navigation bars.menus into good-looking navigation bars.► Navigation Bar = List of LinksNavigation Bar = List of Links► A navigation bar needs standard HTML as a A navigation bar needs standard HTML as a

base.base.► In our examples we will build the navigation In our examples we will build the navigation

bar from a standard HTML list.bar from a standard HTML list.

Page 102: Advanced Cascading Style Sheets

Lesson 10: Lesson 10: Navigation MenusNavigation Menus

► A navigation bar is basically a list of links, so A navigation bar is basically a list of links, so using the <ul> and <li> elements makes using the <ul> and <li> elements makes perfect sense:perfect sense:

► ExampleExample► <ul><ul>

<li><a href="default.asp">Home</a></li><li><a href="default.asp">Home</a></li><li><a href="news.asp">News</a></li><li><a href="news.asp">News</a></li><li><a <li><a href="contact.asp">Contact</a></li>href="contact.asp">Contact</a></li><li><a href="about.asp">About</a></li><li><a href="about.asp">About</a></li></ul></ul>Try it yourself »Try it yourself »

Page 103: Advanced Cascading Style Sheets

Lesson 10: Lesson 10: Navigation MenusNavigation Menus

► Now let's remove the bullets and the Now let's remove the bullets and the margins and padding from the list:margins and padding from the list:

► ExampleExample► ulul

{{list-style-type:none;list-style-type:none;margin:0;margin:0;padding:0;padding:0;}}Try it yourself »Try it yourself »

Page 104: Advanced Cascading Style Sheets

Lesson 10: Lesson 10: Vertical Navigation Vertical Navigation MenusMenus

► To build a vertical navigation bar we only need to style the To build a vertical navigation bar we only need to style the <a> elements, in addition to the code above:<a> elements, in addition to the code above:

► ExampleExample► aa

{{display:block;display:block;width:60px;width:60px;}}Try it yourself »Try it yourself »

► Example explained:Example explained:► display:block - Displaying the links as block elements makes display:block - Displaying the links as block elements makes

the whole link area clickable (not just the text), and it allows the whole link area clickable (not just the text), and it allows us to specify the width us to specify the width

► width:60px - Block elements take up the full width available width:60px - Block elements take up the full width available by default. We want to specify a 60 px widthby default. We want to specify a 60 px width

Page 105: Advanced Cascading Style Sheets

Lesson 10: Lesson 10: Horizontal Navigation Horizontal Navigation MenusMenus

► There are two ways to create a horizontal navigation bar. There are two ways to create a horizontal navigation bar. Using Using inlineinline or or floatingfloating list items. list items.

► Both methods work fine, but if you want the links to be the Both methods work fine, but if you want the links to be the same size, you have to use the floating method.same size, you have to use the floating method.

► Inline List ItemsInline List Items► One way to build a horizontal navigation bar is to specify the One way to build a horizontal navigation bar is to specify the

<li> elements as inline, in addition to the "standard" code <li> elements as inline, in addition to the "standard" code above:above:

► ExampleExample► lili

{{display:inline;display:inline;}}Try it yourself »Try it yourself » Example explained: Example explained:

► display:inline; - By default, <li> elements are block elements. display:inline; - By default, <li> elements are block elements. Here, we remove the line breaks before and after each list Here, we remove the line breaks before and after each list item, to display them on one lineitem, to display them on one line

Page 106: Advanced Cascading Style Sheets

Lesson 10: Lesson 10: Navigation MenusNavigation Menus Floating List ItemsFloating List Items

► In the example above the links have different widths.In the example above the links have different widths.► For all the links to have an equal width, float the <li> elements and For all the links to have an equal width, float the <li> elements and

specify a width for the <a> elementsspecify a width for the <a> elements► ExampleExample► lili

{{float:left;float:left;}}aa{{display:block;display:block;width:60px;width:60px;}}Try it yourself »Try it yourself »

► Example explained:Example explained: float:left - use float to get block elements to slide next to each other float:left - use float to get block elements to slide next to each other display:block - Displaying the links as block elements makes the whole link display:block - Displaying the links as block elements makes the whole link

area clickable (not just the text), and it allows us to specify the width area clickable (not just the text), and it allows us to specify the width width:60px - Since block elements take up the full width available, they cannot width:60px - Since block elements take up the full width available, they cannot

float next to each other. We specify the width of the links to 60pxfloat next to each other. We specify the width of the links to 60px

Page 107: Advanced Cascading Style Sheets

Lesson 10 Assignment:Lesson 10 Assignment:CSS Navigation MenusCSS Navigation Menus

► Create a new external notepad CSS style Create a new external notepad CSS style sheet and an HTML document that shows sheet and an HTML document that shows a 1 example of a vertical navigation bar a 1 example of a vertical navigation bar and 1 horizontal navigation bar each with and 1 horizontal navigation bar each with 4 buttons. 4 buttons.

► Save Your File as css-navigationbar.html Save Your File as css-navigationbar.html and your style sheet into your folder.and your style sheet into your folder.

Page 108: Advanced Cascading Style Sheets

Culminating Unit Culminating Unit Performance TaskPerformance Task

►Daily News Web PageDaily News Web Page

Page 109: Advanced Cascading Style Sheets

Optional Lesson 11: Optional Lesson 11:

CSS 3CSS 3

Page 110: Advanced Cascading Style Sheets

CSS 3CSS 3

►CSS is used to control the style and CSS is used to control the style and layout of Web pages.layout of Web pages.

►CSS3 is the latest standard for CSS.CSS3 is the latest standard for CSS.

Page 111: Advanced Cascading Style Sheets

CSS3 ExampleCSS3 Example

divdiv{{transform:rotate(30deg);transform:rotate(30deg);}}Try it yourself »Try it yourself »

Works on Chrome and Firefox not IE.

CSS3 Reference table:CSS3 Reference table:http://w3schools.com/css3/css3_reference.asp