SlideShare a Scribd company logo
Advanced  CSS by:  Alexandra Vlachakis Sandy Creek High School, Fayette County Schools Content and Resources Used With Permission:  Interact With Web Standards. Copyright 2010.  Erin Anderson et. Al. W3 Schools. www.w3schools.com. 12-25-11.
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.
CSS Review
Selector Review Definition: identifies the HTML elements that the rule will be applied to, identified by the actual element name, e.g. <body>, or by other means such as  class  attribute values.  Example: *The selector is normally the HTML element you want to style
Selector Review selector {property:value} body {color: black} If  the value is multiple words, put quotes around the value  p {font-family:&quot;sans serif&quot;} If you want to specify more than one property, you must separate each property with a semicolon. The example below shows how to define a center aligned paragraph, with a red text color p {text-align:center;color:red}
To make the style definitions more readable, you can describe one property on each line, like this: p {  text-align:center; color:black; font-family:arial  } Selector Review
Property & Value Review Definition:  The property is the style attribute you want to change. Each  property  has a  value .   *Properties are separated from their respective values by  colons  : * Pairs are separated from each other by  semicolons  ;
Declaration Review Definition: Each CSS line that includes property and value *Each declaration consists of a property and a value.
Style Sheets Review When a browser reads a style sheet, it will format the document according to it. There are three ways of inserting a style sheet: External Style Sheet  Internal Style Sheet Inline Styles Instructor Note: Students will be using External Style Sheets for all the lesson that follow
Class Selectors Review Class  -   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 any HTML elements with the same class.  The class selector uses the HTML class attribute, and is defined with a &quot;.&quot;  In the example below, all HTML elements with class=&quot;center&quot; will be center-aligned: .center {text-align:center;}
id Selectors Review In addition to setting a style for a HTML element, CSS allows you to specify your own selectors called &quot;id&quot; and &quot;class&quot;. id  -   The id selector is used to specify a style for a single, unique element.  The id selector uses the id attribute of the HTML element, and is defined with a &quot;#&quot;.  The style rule below will be applied to the element with id=&quot;para1&quot;:  #para1 {text-align:center;color:red;}
Class and id Selectors Review In the image below what is the h1 selector an ID or a Class? # .
How well do you know CSS? What are CSS style sheets? Why do web developers use CSS style sheets? What are the components of a CSS rule? What is the difference between using a CSS ID and Class? Why do web developers use CSS comments? How do you apply an internal CSS style? How do you apply an external CSS style sheet? How do you apply an inline CSS style? What is the CSS rule for applying colors? What are the units of measurement used to specify size and dimension in CSS?
End Review The next slides are new content.  If students need more review on CSS please see Unit 6 Introduction To CSS
Lesson 1:  Alpha or Transparent Colors
Alpha  –RGB(a) has the ability to make items transparent (or see-through) The “a” stands for alpha which means transparency. Opposite of alpha is opacity which the measurement of how solid a color is. CSS example:  div{color: RGBa(255,0,0, 0.7) } Lesson 1:  Alpha or Transparent Colors
Lesson 1 Assignment Part 1 of 2: CSS Alpha Color HTML Page Open A New Notepad Document Type the following Code. <html> <title> CSS Transparency Example </title> <head> <link href=&quot;style.css&quot; type=&quot;text/css&quot; rel=&quot;stylesheet&quot;> </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.html
  Lesson 1 Assignment Part 2 of 2:  CSS Alpha Color Style Sheet Open A New Notepad Document Type the following Code. div { background-color:rgba(240,250,59,.8); width:800px; } Save Your File as style.css Open your  alpha-color.html web page. Check your new color application. Try other color combinations. Browser Compatibility Note: Alpha color is not compatible with IE8 or below but will work on Firefox. Instructor Note: After creating the file have students manipulate the color values to discover other color combinations using RGB(a)
Lesson 2:  Block elements
Lesson 2:  Block elements A block element is an element that takes up the full width available, and has a line break before and after it. Examples of block elements: <h1>  <p>  <div> You should be familiar with <h1> and <p> tags from HTML Can anyone tell us what they are used for? The <div> tag defines a division or a section in an HTML document. The <div> tag is often used to group block-elements to format them with styles. In the next assignment you will aligning <div> tags using CSS
Lesson 2 Assignment: Div Tags & Block elements Open A New Notepad Document Create an external CSS style sheet & a HTML Document  with 2 div 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 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-block.html page.  Browser Compatibility Note rgb(a) does not work in IE8.
Lesson 3:  CSS Positioning
Lesson 3:  CSS Positioning The CSS positioning properties allow you to position an element like the ones we discussed in lesson 2. It can also place an element behind another, and specify what should happen when an element's content is too big. Elements can be positioned using the top, bottom, left, and right properties. However, these properties will not work unless the position property is set first.  They also work differently depending on the positioning method. There are four different positioning methods. Source:  http://www.w3schools.com/Css/css_positioning.asp
Lesson 3:  CSS Positioning Static Positioning HTML elements are positioned static by default. A static positioned element is always positioned according to the normal flow of the page. Static positioned elements are not affected by the top, bottom, left, and right properties. Fixed Positioning An element with fixed position is positioned relative to the browser window. It will not move even if the window is scrolled: Example p.pos_fixed { position:fixed; top:30px; right:5px; } Note:  Internet Explorer supports the fixed value only if a !DOCTYPE is specified. Fixed positioned elements are removed from the normal flow. The document and other elements behave like the fixed positioned element does not exist. Fixed positioned elements can overlap other elements. Source:  http://www.w3schools.com/Css/css_positioning.asp
SPECIAL PAUSE FOR  DOCTYPE! Since we were on the topic of browser compatibility this is a good spot to stop and talk about DOCTYPE DOCTYPE  = Document Type Definition (abbreviation DTD) Every single HTML page should have a DOCTYPE to be valid for HTML (or XHTML) For Example: <!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN” “http://www.w3.org/TR/html4/strict.dtd”>
SPECIAL PAUSE FOR  DOCTYPE! DOCTYPE is important because it sets rules that the HTML document should follow to be correct.  For example what version of HTML the author is using, the rendering mode to use when rendering each HTML document.  If you do not define DOCTYPE the browsers will handle and render the document anyway. Browsers need to make sense of the all the strange things that come across the web  Without DOCTYPE the results may not look like what you intended because of something called  DOCTYPE sniffing  or  DOCTYPE switching .
SPECIAL PAUSE FOR  DOCTYPE! A list of DOCTYPES can be found at  http://www.w3.org/QA/2002/04/valid-dtd-list.html You can test whether your HTML document is following the rules outlined correctly by going to  http://validator.w3.org/
Lesson 3:  CSS Positioning Relative Positioning A relative positioned element is positioned relative to its normal position. Example h2.pos_left { position:relative; left:-20px; } h2.pos_right { position:relative; left:20px; } Try it yourself »  The content of relatively positioned elements can be moved and overlap other elements, but the reserved space for the element is still preserved in the normal flow. Example h2.pos_top { position:relative; top:-50px; } Try it yourself »  Relatively positioned elements are often used as container blocks for absolutely positioned elements. Source:  http://www.w3schools.com/Css/css_positioning.asp
Lesson 3:  CSS Positioning Absolute Positioning An absolute position element is positioned relative to the first parent element that has a position other than static. If no such element is found, the containing block is <html>: Example h2 { position:absolute; left:100px; top:150px; } Try it yourself »  Absolutely positioned elements are removed from the normal flow. The document and other elements behave like the absolutely positioned element does not exist. Absolutely positioned elements can overlap other elements. Source:  http://www.w3schools.com/Css/css_positioning.asp
Lesson 3:  CSS Positioning Overlapping Elements When elements are positioned outside the normal flow, they can overlap other elements. The z-index property specifies the stack order of an element (which element should be placed in front of, or behind, the others). An element can have a positive or negative stack order: Example img { position:absolute; left:0px; top:0px; z-index:-1 } Try it yourself »  An element with greater stack order is always in front of an element with a lower stack order. Note:  If two positioned elements overlap, without a z-index specified, the element positioned last in the HTML code will be shown on top. Source:  http://www.w3schools.com/Css/css_positioning.asp
Lesson 3 Assignment: CSS Positioning Open A New Notepad Document Create an external CSS style sheet & a HTML Document  with 4 div tags in HTML and 4 different styles in the external CSS that demonstrate CSS position.  See example. You can use the examples at the following link as a guide:  http://www.w3schools.com/Css/css_positioning.asp   to create your document. CSS Style Example: div { left:0px; top:0px; z-index:-1 } HTML Example: <div> This box is positioned relative </div> Save Your Files as style.css and css-position.html in the same folder
Lesson 4:  Aligning Block Elements
Lesson 4:  Aligning Block Elements In CSS, several properties are used to align elements horizontally. Center Aligning Using the margin Property Block elements can be aligned by setting the left and right margins to &quot;auto&quot;. Note:  Using margin:auto will not work in IE 8 and earlier,  unless a !DOCTYPE is declared.
Lesson 4:  Aligning Block Elements Setting the left and right margins  to auto specifies that they should split the available margin equally. The result is a centered element: Example .center { margin-left:auto; margin-right:auto; width:70%; background-color:#b0e0e6; } Try it yourself »   Tip:  Aligning has no effect if the width is 100%. Note:  In IE 5 there is a margin handling bug for block elements. To make the example above work in IE5, add some extra code.  Try it yourself Source:  http://www.w3schools.com/css/css_align.asp
Lesson 4:  Aligning Block Elements Crossbrowser Compatibility Issues When aligning elements like this, it is always a good idea to predefine margin and padding for the <body> element. This is to avoid visual differences in different browsers. There is also another problem with IE when using the position property.  If a container element (in our case <div class=&quot;container&quot;>) has a specified width, and the !DOCTYPE declaration is missing, IE will add a 17px margin on the right side.  This seems to be space reserved for a scrollbar.  Always set the !DOCTYPE declaration when using the position property.  Source:  http://www.w3schools.com/css/css_align.asp
Lesson 4:  Aligning Block Elements Example body { margin:0; padding:0; } .container { position:relative; width:100%; } .right { position:absolute; right:0px; width:300px; background-color:#b0e0e6; } Try it yourself » Source:  http://www.w3schools.com/css/css_align.asp
Lesson 4:  Aligning Block Elements Left and Right Aligning Using the float Property One method of aligning elements is to use the float property: Example .right { float:right; width:300px; background-color:#b0e0e6; } Try it yourself »
Lesson 4:  Aligning Block Elements Cross browser Compatibility Issues When aligning elements like this, it is always a good idea to predefine margin and padding for the <body> element.  This is to avoid visual differences in different browsers. There is also another problem with IE when using the float property.  If the !DOCTYPE declaration is missing, IE will add a 17px margin on the right side.  This seems to be space reserved for a scrollbar.  Always set the !DOCTYPE declaration when using the float property
Lesson 4:  Aligning Block Elements Example body { margin:0; padding:0; } .right { float:right; width:300px; background-color:#b0e0e6; } Try it yourself »
Lesson 5:  Float
Lesson 5:  Float With CSS float, an element can be pushed to the left or right, allowing other elements to wrap around it. Float is very often used for images, but it is also useful when working with layouts. Source: http://w3schools.com/css/css_float.asp
Lesson 5:  How Elements Float Elements are floated horizontally, this means that an element 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. Usually this means all the way to the left or right of the containing element. The elements after the floating element will flow around it. The elements before the floating element will not be affected. If an image is floated to the right, a following text flows around it, to the left: Example img { float:right; } Try it yourself »   Source: http://w3schools.com/css/css_float.asp
Lesson 5:  Float Floating Elements Next to Each Other If you place several floating elements after each other, they will float next to each other if there is room. Here we have made an image gallery using the float property: Example .thumbnail  { float:left; width:110px; height:90px; margin:5px; } Try it yourself »   Source: http://w3schools.com/css/css_float.asp
Lesson 5:  Float Turning off Float - Using Clear Elements after the floating element will flow around it. To avoid this, use the clear property. The clear property specifies which sides of an element other floating elements are not allowed. Add a text line into the image gallery, using the clear property: Example .text_line { clear:both; } Try it yourself »   Source: http://w3schools.com/css/css_float.asp
Lesson 5 Assignment: CSS Align and Float Open A New Notepad Document Create an external CSS style sheet & a HTML Document  with 6 div tags in HTML and 4 different styles in the external CSS that demonstrate CSS align and float. See example. You can use the examples at the following link as a guide:  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 folder
Lesson 6:  Lists
Lesson 6:  Lists The CSS list properties allow you to: Set different list item markers for ordered lists  Set different list item markers for unordered lists  Set an image as the list item marker Source:  http://w3schools.com/css/css_list.asp
Lesson 6:  Lists In HTML, there are two types of lists: unordered lists - the list items are marked with bullets  ordered lists - the list items are marked with numbers or letters What is the tag in HTML that sets up an ordered list? What is the tag in HTML that sets up an unordered list?  With CSS, lists can be styled further, and images can be used as the list item marker. Source:  http://w3schools.com/css/css_list.asp
Lesson 6:  Different List Item Markers The type of list item marker is specified with the list-style-type property: Example ul.a {list-style-type: circle;} ul.b {list-style-type: square;} ol.c {list-style-type: upper-roman;} ol.d {list-style-type: lower-alpha;} Try it yourself » Source:  http://w3schools.com/css/css_list.asp
Lesson 6 Assignment: CSS Lists Unordered Create a web page with multiple  unordered  CSS list types. Values for Unordered Lists none = no marker disc circle square
Lesson 6 Assignment: CSS Lists Ordered Create an HTML web page with 2 ordered and 2 unordered CSS list types in an external style sheet. See Example. Values for Ordered Lists Examples: Armenian = The marker is traditional Armenian numbering Decimal = The marker is a number  decimal-leading-zero = The marker is a number padded by initial zeros (01, 02, 03, etc.) Georgian = The marker is traditional Georgian numbering (an, ban, gan, etc.) lower-alpha = The marker is lower-alpha (a, b, c, d, e, etc.) lower-greek = The marker is lower-greek (alpha, beta, gamma, 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.) 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-roman = The marker is upper-roman (I, II, III, IV, V, etc.)
Lesson 6:  Lists Using Images An Image as The List Item Marker To specify an image as the list item marker, use the list-style-image property: Example ul { list-style-image: url('sqpurple.gif'); } Try it yourself »   The example above does not display equally in all browsers. IE and Opera will display the image-marker a little bit higher than Firefox, Chrome, and Safari. More list examples:  http://w3schools.com/css/tryit.asp?filename= trycss_list-style-type_all
Lesson 6 Assignment: CSS Lists With An Image Open your css-lists.html web page in notepad add 2 list types in the external style sheet that have pictures as bullets.  See Example. You can download a royalty free picture from  use as a bullet.
Lesson 7:  Fonts & Text On Web Pages
Lesson 7:  Points are For Print Many Web designers have gotten into the bad habit of using point sizes to define their font sizes on the screen.  But points are a print unit of measure, and the Web is usually viewed on the screen.  This means that when you specify 14-point type, it might display much larger or smaller than you expect.  The most common place this is noticed is between Macintosh and Windows. Macintosh typically displays things almost 25% smaller than the same page on Windows.  The next few slides will explain how to adjust fonts to work well on web pages.
Lesson 7:  Setting Font Size Font Size The font-size property sets the size of the text. Being able to manage the text size is important in web design. However, you should not use font size adjustments to make paragraphs look like headings, or headings look like paragraphs. Always use the proper HTML tags, like <h1> - <h6> for headings and <p> for paragraphs. The font-size value can be an absolute, or relative size.
Absolute size: Sets the text to a specified size  Does not allow a user to change the text size in all browsers (bad for accessibility reasons)  Absolute size is useful when the physical size of the output is known Lesson 7:  Setting Font Size
Relative size: Sets the size relative to surrounding elements  Allows a user to change the text size in browsers If you do not specify a font size, the default size for normal text, like paragraphs, is 16px (16px=1em). Lesson 7:  Setting Font Size
Lesson 7:  Setting Font Size with Pixels Set Font Size With Pixels Setting the text size with pixels, gives you full control over the text size: Example h1 {font-size:40px;} h2 {font-size:30px;} p {font-size:14px;} 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).
Lesson 7:  Setting Font Size with Em Set Font Size With Em To avoid the resizing problem with Internet Explorer, many developers use em instead of pixels. The em size unit is recommended by the W3C. 1em is equal to the current font size. The default text size in browsers is 16px. So, the default size of 1em is 16px. The size can be calculated from pixels to em using this formula:  pixels /16= em Example h1 {font-size:2.5em;} /* 40px/16=2.5em */ h2 {font-size:1.875em;} /* 30px/16=1.875em */ p {font-size:0.875em;} /* 14px/16=0.875em */ Try it yourself »   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 the text size in all browsers.  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 should when made smaller.
Lesson 7:  Setting Font Size with Em Use a Combination of Percent and Em The solution that works in all browsers, is to set a default font-size in percent for the body element: Example body {font-size:100%;} h1 {font-size:2.5em;} h2 {font-size:1.875em;} p {font-size:0.875em;} Try it yourself »   Our code now works great! It shows the same text size in all browsers, and allows all browsers to zoom or resize the text!
Lesson 7:  Font   Style The font-style property is mostly used to specify italic text. This property has three values: normal - The text is shown normally  italic - The text is shown in italics  oblique - The text is &quot;leaning&quot; (oblique is very similar to italic, but less supported) Example p.normal {font-style:normal;} p.italic {font-style:italic;} p.oblique {font-style:oblique;} h1 {font-style: italic} h2 {font-style: normal} p {font-style: oblique} Try it yourself »
Lesson 7:  CSS Font Families In CSS, there are two types of font family names: generic family  - a group of font families with a similar look (like &quot;Serif&quot; or &quot;Monospace&quot;)  font family  - a specific font family (like &quot;Times New Roman&quot; or &quot;Arial&quot;) Generic family  Serif (Times New Roman, Georgia) Serif fonts have small lines at the ends on some characters Sans-serif (Arial, Verdana) &quot;Sans&quot; means without - these fonts do not have the lines at the ends of characters Monospace (Courier, New Lucida, Console) All monospace characters have the same width
Lesson 7:  CSS Font Families The font family of a text is set with the font-family property. The font-family property should hold several font names as a &quot;fallback&quot; system. If the browser does not support the first font, it tries the next font. 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 other fonts are available.  Note : If the name of a font family is more than one word, it must be in quotation marks, like font-family: &quot;Times New Roman&quot;. More than one font family  is specified in a comma-separated list Example p{font-family:&quot;Times New Roman&quot;, Times, serif;}  Try it yourself »
Lesson 7:  Font Bold Examples to specify bold by thickness: p.normal {font-weight: normal} p.thick {font-weight: bold} p.thicker {font-weight: 900}
Lesson 7:  Setting all the Styles in  one line for FONT Shortcut Example: p { font: italic small-caps 900 12px arial }
Lesson 7:  Text Color The color property is used to set the color of the text. The color can be specified by: name - a color name, like &quot;red&quot;  RGB - an RGB value, like &quot;rgb(255,0,0)&quot;  Hex - a hex value, like &quot;#ff0000&quot; The default color for a page is defined in the body selector. Example body {color:blue;} h1 {color:#00ff00;} h2 {color:rgb(255,0,0);} Try it yourself »   For W3C compliant CSS: If you define the color property, you must also define the background-color property.
Lesson 7:  Text Alignment The text-align property is used to set the horizontal alignment of a text. Text can be centered, or aligned to the left or right, or justified. When text-align is set to &quot;justify&quot;, each line is stretched so that every line has equal width, and the left and right margins are straight (like in magazines and newspapers). Example h1 {text-align:center;} p.date {text-align:right;} p.main {text-align:justify;}  Try it yourself »
Lesson 7:  Text Decoration The text-decoration property is used to set or remove decorations from text. The text-decoration property is mostly used to remove underlines from links for design purposes Example a {text-decoration:none;}  Try it yourself »   It can also be used to decorate text Example h1 {text-decoration:overline;} h2 {text-decoration:line-through;} h3 {text-decoration:underline;} h4 {text-decoration:blink;} Try it yourself »   It is not recommended to underline text that is not a link, as this often confuses users.
Lesson 7:  Text Transformation The text-transform property is used to specify uppercase and lowercase letters in a text. It can be used to turn everything into uppercase or lowercase letters, or capitalize the first letter of each word. Example p.uppercase {text-transform:uppercase;} p.lowercase {text-transform:lowercase;} p.capitalize {text-transform:capitalize;} Try it yourself »
Lesson 7:  Text Indentation The text-indentation property is used to specify the indentation of the first line of a text. Example p {text-indent:50px;} Try it yourself »
Lesson 7 Assignment: CSS Fonts & Text Create a new external notepad CSS style sheet and an HTML document that shows 10 paragraphs with different examples of formatting text.  Save Your File as css-fonts.html and your style sheet into your folder.
Lesson 8:  CSS Tables
Lesson 8:  HTML Tables Review Tables are defined with the <table> tag. A table is divided into rows (with the <tr> tag),  each row is divided into data cells (with the <td> tag).  td stands for &quot;table data,&quot; and holds the content of a data cell.  A <td> tag can contain text, links, images, lists, forms, other tables, etc.
Lesson 8:  HTML Tables Review Table Example <table border=&quot;1&quot;> <tr> <td>row 1, cell 1</td> <td>row 1, cell 2</td> </tr> <tr> <td>row 2, cell 1</td> <td>row 2, cell 2</td> </tr> </table>
Lesson 8:  CSS Table Borders The look of an HTML table can be greatly improved with CSS Table Borders To specify table borders in CSS, use the border property. The example below specifies a black border for table, th, and td elements: Example table, th, td { border: 1px solid black; } Try it yourself »
Lesson 8:  Table Width and Height Width and height of a table is defined by the width and height properties. The example below sets the width of the table to 100%, and the height of the th elements to 50px: Example table  { width:100%; } th { height:50px; }  Try it yourself »
Lesson 8:  Table Text Alignment The text in a table is aligned with the text-align and vertical-align properties. The text-align property sets the horizontal alignment, like left, right, or center: Example td { text-align:right; } Try it yourself »  The vertical-align property sets the vertical alignment, like top, bottom, or middle: Example td { height:50px; vertical-align:bottom; } Try it yourself »
Lesson 8:  Table Padding To control the space between the border and content in a table, use the padding property on td and th elements: Example td { padding:15px; } Try it yourself »
Lesson 8:  Table Color The example below specifies the color of the borders, and the text and background color of th elements: Example table, td, th { border:1px solid green; } th { background-color:green; color:white; } Try it yourself »
Lesson 8 Assignment: CSS Table Create a new external notepad CSS style sheet and an HTML document that shows a table with 5 rows and 3 columns with different examples of formatting text inside of it.  Save Your File as css-table.html and your style sheet into your folder.
Lesson 9:  White Space & Borders
Lesson 9:  White Space In web pages white space will allow you to define the look and feel of a web page by providing white area around elements. Let’s take a look at some pages that make good use of white space.  http://online.wsj.com/home-page http://www.csszengarden.com/?cssfile=/206/206.css&page=0 http:// www.csszengarden.com/?cssfile =/210/210.css&page=0
Lesson 9:  Borders CSS Border Properties The CSS border properties allow you to specify the style and color of an element's border. Border Style The border-style property specifies what kind of border to display. None of the border properties will have ANY effect unless the  border-style  property is set!
Lesson 9:  Border-style values: none: Defines no border dotted: Defines a dotted border dashed: Defines a dashed border solid: Defines a solid border double: Defines two borders. The width of the two borders are the same as the border-width value groove: Defines a 3D grooved border. The effect depends on the border-color value ridge: Defines a 3D ridged border. The effect depends on the border-color value inset: Defines a 3D inset border. The effect depends on the border-color value outset: Defines a 3D outset border. The effect depends on the border-color value
Lesson 9:  Border Width The border-width property is used to set the width of the border. The width is set in pixels, or by using one of the three pre-defined values: thin, medium, or thick. Note:  The &quot;border-width&quot; property does not work if it is used alone. Use the &quot;border-style&quot; property to set the borders first. Example p.one { border-style:solid; border-width:5px; } p.two { border-style:solid; border-width:medium; }  Try it yourself »
Lesson 9:  Border Color The border-color property is used to set the color of the border. The color can be set by: name - specify a color name, like &quot;red&quot;  RGB - specify a RGB value, like &quot;rgb(255,0,0)&quot;  Hex - specify a hex value, like &quot;#ff0000&quot; You can also set the border color to &quot;transparent&quot;. Note:  The &quot;border-color&quot; property does not work if it is used alone. Use the &quot;border-style&quot; property to set the borders first. Example p.one { border-style:solid; border-color:red; } p.two { border-style:solid; border-color:#98bf21; }  Try it yourself »
Lesson 9:  Border - Individual sides In CSS it is possible to specify different borders for different sides Example p { border-top-style:dotted; border-right-style:solid; border-bottom-style:dotted; border-left-style:solid; } Try it yourself »   The example above can also be set with a single property Example border-style:dotted solid; Try it yourself »
Lesson 9:  Border - Shorthand property As you can see from the examples above, there are many properties to consider when dealing with borders. To shorten the code, it is also possible to specify all the border properties in one property. This is called a shorthand property. The shorthand property for the border properties is &quot;border&quot;: Example border:5px solid red; Try it yourself »   When using the border property, the order of the values are: border-width  border-style  border-color 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 order.
Lesson 9:  White Space - Margins The CSS margin properties define the space (white space) around elements. The 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. Possible Values Auto - The browser sets the margin. The result of this is dependant of the browser Length -  Defines a fixed margin (in pixels, pt, em, etc.)  %  -  Defines a margin in % of the containing element.  It is possible to use negative values, to overlap content.
Lesson 9:  White Space - Margins The margin property can have from one to four values. margin:25px 50px 75px 100px;  top margin is 25px  right margin is 50px  bottom margin is 75px  left margin is 100px margin:25px 50px 75px;   top margin is 25px  right and left margins are 50px  bottom margin is 75px margin:25px 50px;   top and bottom margins are 25px  right and left margins are 50px margin:25px;   all four margins are 25px
Lesson 9:  White Space - Margins Margin - Shorthand property To shorten the code, it is possible to specify all the margin properties in one property. This is called a shorthand property. The shorthand property for all the margin properties is &quot;margin&quot;: Example margin:100px 50px; Try it yourself »
Lesson 9:  White Space - Margins Margin - Individual sides In CSS, it is possible to specify different margins for different sides: Example margin-top:100px; margin-bottom:100px; margin-right:50px; margin-left:50px; Try it yourself »
Lesson 9:  White Space - Padding The CSS padding properties define the space between the element border and the element content. The padding clears an area around the content (inside the border) of an element.  The padding is affected by the background color of the element. The top, right, bottom, and left padding can be changed independently using separate properties.  A shorthand padding property can also be used, to change all paddings at once. Possible Values Length -  Defines a fixed padding (in pixels, pt, em, etc.) % -  Defines a padding in % of the containing element
Lesson 9:  White Space - Padding Padding - Individual sides In CSS, it is possible to specify different padding for different sides: Example padding-top:25px; padding-bottom:25px; padding-right:50px; padding-left:50px; Try it yourself »
Lesson 9:  White Space - Padding Padding - Shorthand property To shorten the code, it is possible to specify all the padding properties in one property. This is called a shorthand property. The shorthand property for all the padding properties is &quot;padding&quot;:
Lesson 9:  White Space - Padding Padding - Individual sides In CSS, it is possible to specify different padding for different sides: Example padding-top:25px; padding-bottom:25px; padding-right:50px; padding-left:50px; Try it yourself »
Lesson 9:  White Space - Padding The padding property can have from one to four values. padding:25px 50px 75px 100px;  top padding is 25px  right padding is 50px  bottom padding is 75px  left padding is 100px padding:25px 50px 75px;   top padding is 25px  right and left paddings are 50px  bottom padding is 75px padding:25px 50px;   top and bottom paddings are 25px  right and left paddings are 50px padding:25px;   all four paddings are 25px
Lesson 9 Assignment: CSS White Space Create a new external notepad CSS style sheet and an HTML document that shows a 4 div tags with 5 examples of white space.  Save Your File as css-whitespace.html and your style sheet into your folder.
Lesson 10:  Navigation Menus
Lesson 10:  Navigation Menus Navigation Bars Having easy-to-use navigation is important for any web site. With CSS you can transform boring HTML menus into good-looking navigation bars. Navigation Bar = List of Links A navigation bar needs standard HTML as a base. In our examples we will build the navigation bar from a standard HTML list.
Lesson 10:  Navigation Menus A navigation bar is basically a list of links, so using the <ul> and <li> elements makes perfect sense: Example <ul> <li><a href=&quot;default.asp&quot;>Home</a></li> <li><a href=&quot;news.asp&quot;>News</a></li> <li><a href=&quot;contact.asp&quot;>Contact</a></li> <li><a href=&quot;about.asp&quot;>About</a></li> </ul> Try it yourself »
Lesson 10:  Navigation Menus Now let's remove the bullets and the margins and padding from the list: Example ul { list-style-type:none; margin:0; padding:0; } Try it yourself »
Lesson 10:  Vertical Navigation Menus To build a vertical navigation bar we only need to style the <a> elements, in addition to the code above: Example a { display:block; width:60px; } Try it yourself »   Example explained: 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  width:60px - Block elements take up the full width available by default. We want to specify a 60 px width
Lesson 10:  Horizontal Navigation Menus   There are two ways to create a horizontal navigation bar. Using  inline  or  floating  list items. Both methods work fine, but if you want the links to be the same size, you have to use the floating method. Inline List Items One way to build a horizontal navigation bar is to specify the <li> elements as inline, in addition to the &quot;standard&quot; code above: Example li { display:inline; } Try it yourself »  Example explained: display:inline; - By default, <li> elements are block elements. Here, we remove the line breaks before and after each list item, to display them on one line
Lesson 10:  Navigation Menus   Floating List Items In the example above the links have different widths. For all the links to have an equal width, float the <li> elements and specify a width for the <a> elements Example li { float:left; } a { display:block; width:60px; } Try it yourself »   Example explained: 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 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 float next to each other. We specify the width of the links to 60px
Lesson 10 Assignment: CSS Navigation Menus Create a new external notepad CSS style sheet and an HTML document that shows a 1 example of a vertical navigation bar and 1 horizontal navigation bar each with 4 buttons.  Save Your File as css-navigationbar.html and your style sheet into your folder.
Culminating Unit Performance Task   Daily News Web Page
Optional Lesson 11:  CSS 3
CSS 3 CSS is used to control the style and layout of Web pages. CSS3 is the latest standard for CSS.
CSS3 Example div { transform:rotate(30deg); } Try it yourself » Works on Chrome and Firefox not IE. CSS3 Reference table: http://w3schools.com/css3/css3_reference.asp

More Related Content

Advanced Cascading Style Sheets

  • 1. Advanced CSS by: Alexandra Vlachakis Sandy Creek High School, Fayette County Schools Content and Resources Used With Permission: Interact With Web Standards. Copyright 2010. Erin Anderson et. Al. W3 Schools. www.w3schools.com. 12-25-11.
  • 2. 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.
  • 4. Selector Review Definition: identifies the HTML elements that the rule will be applied to, identified by the actual element name, e.g. <body>, or by other means such as class attribute values. Example: *The selector is normally the HTML element you want to style
  • 5. Selector Review selector {property:value} body {color: black} If  the value is multiple words, put quotes around the value p {font-family:&quot;sans serif&quot;} If you want to specify more than one property, you must separate each property with a semicolon. The example below shows how to define a center aligned paragraph, with a red text color p {text-align:center;color:red}
  • 6. To make the style definitions more readable, you can describe one property on each line, like this: p { text-align:center; color:black; font-family:arial } Selector Review
  • 7. Property & Value Review Definition: The property is the style attribute you want to change. Each property has a value . *Properties are separated from their respective values by colons : * Pairs are separated from each other by semicolons ;
  • 8. Declaration Review Definition: Each CSS line that includes property and value *Each declaration consists of a property and a value.
  • 9. Style Sheets Review When a browser reads a style sheet, it will format the document according to it. There are three ways of inserting a style sheet: External Style Sheet Internal Style Sheet Inline Styles Instructor Note: Students will be using External Style Sheets for all the lesson that follow
  • 10. Class Selectors Review Class - 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 any HTML elements with the same class. The class selector uses the HTML class attribute, and is defined with a &quot;.&quot; In the example below, all HTML elements with class=&quot;center&quot; will be center-aligned: .center {text-align:center;}
  • 11. id Selectors Review In addition to setting a style for a HTML element, CSS allows you to specify your own selectors called &quot;id&quot; and &quot;class&quot;. id - The id selector is used to specify a style for a single, unique element. The id selector uses the id attribute of the HTML element, and is defined with a &quot;#&quot;. The style rule below will be applied to the element with id=&quot;para1&quot;: #para1 {text-align:center;color:red;}
  • 12. Class and id Selectors Review In the image below what is the h1 selector an ID or a Class? # .
  • 13. How well do you know CSS? What are CSS style sheets? Why do web developers use CSS style sheets? What are the components of a CSS rule? What is the difference between using a CSS ID and Class? Why do web developers use CSS comments? How do you apply an internal CSS style? How do you apply an external CSS style sheet? How do you apply an inline CSS style? What is the CSS rule for applying colors? What are the units of measurement used to specify size and dimension in CSS?
  • 14. End Review The next slides are new content. If students need more review on CSS please see Unit 6 Introduction To CSS
  • 15. Lesson 1: Alpha or Transparent Colors
  • 16. Alpha –RGB(a) has the ability to make items transparent (or see-through) The “a” stands for alpha which means transparency. Opposite of alpha is opacity which the measurement of how solid a color is. CSS example: div{color: RGBa(255,0,0, 0.7) } Lesson 1: Alpha or Transparent Colors
  • 17. Lesson 1 Assignment Part 1 of 2: CSS Alpha Color HTML Page Open A New Notepad Document Type the following Code. <html> <title> CSS Transparency Example </title> <head> <link href=&quot;style.css&quot; type=&quot;text/css&quot; rel=&quot;stylesheet&quot;> </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.html
  • 18. Lesson 1 Assignment Part 2 of 2: CSS Alpha Color Style Sheet Open A New Notepad Document Type the following Code. div { background-color:rgba(240,250,59,.8); width:800px; } Save Your File as style.css Open your alpha-color.html web page. Check your new color application. Try other color combinations. Browser Compatibility Note: Alpha color is not compatible with IE8 or below but will work on Firefox. Instructor Note: After creating the file have students manipulate the color values to discover other color combinations using RGB(a)
  • 19. Lesson 2: Block elements
  • 20. Lesson 2: Block elements A block element is an element that takes up the full width available, and has a line break before and after it. Examples of block elements: <h1> <p> <div> You should be familiar with <h1> and <p> tags from HTML Can anyone tell us what they are used for? The <div> tag defines a division or a section in an HTML document. The <div> tag is often used to group block-elements to format them with styles. In the next assignment you will aligning <div> tags using CSS
  • 21. Lesson 2 Assignment: Div Tags & Block elements Open A New Notepad Document Create an external CSS style sheet & a HTML Document with 2 div 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 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-block.html page. Browser Compatibility Note rgb(a) does not work in IE8.
  • 22. Lesson 3: CSS Positioning
  • 23. Lesson 3: CSS Positioning The CSS positioning properties allow you to position an element like the ones we discussed in lesson 2. It can also place an element behind another, and specify what should happen when an element's content is too big. Elements can be positioned using the top, bottom, left, and right properties. However, these properties will not work unless the position property is set first. They also work differently depending on the positioning method. There are four different positioning methods. Source: http://www.w3schools.com/Css/css_positioning.asp
  • 24. Lesson 3: CSS Positioning Static Positioning HTML elements are positioned static by default. A static positioned element is always positioned according to the normal flow of the page. Static positioned elements are not affected by the top, bottom, left, and right properties. Fixed Positioning An element with fixed position is positioned relative to the browser window. It will not move even if the window is scrolled: Example p.pos_fixed { position:fixed; top:30px; right:5px; } Note: Internet Explorer supports the fixed value only if a !DOCTYPE is specified. Fixed positioned elements are removed from the normal flow. The document and other elements behave like the fixed positioned element does not exist. Fixed positioned elements can overlap other elements. Source: http://www.w3schools.com/Css/css_positioning.asp
  • 25. SPECIAL PAUSE FOR DOCTYPE! Since we were on the topic of browser compatibility this is a good spot to stop and talk about DOCTYPE DOCTYPE = Document Type Definition (abbreviation DTD) Every single HTML page should have a DOCTYPE to be valid for HTML (or XHTML) For Example: <!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN” “http://www.w3.org/TR/html4/strict.dtd”>
  • 26. SPECIAL PAUSE FOR DOCTYPE! DOCTYPE is important because it sets rules that the HTML document should follow to be correct. For example what version of HTML the author is using, the rendering mode to use when rendering each HTML document. If you do not define DOCTYPE the browsers will handle and render the document anyway. Browsers need to make sense of the all the strange things that come across the web Without DOCTYPE the results may not look like what you intended because of something called DOCTYPE sniffing or DOCTYPE switching .
  • 27. SPECIAL PAUSE FOR DOCTYPE! A list of DOCTYPES can be found at http://www.w3.org/QA/2002/04/valid-dtd-list.html You can test whether your HTML document is following the rules outlined correctly by going to http://validator.w3.org/
  • 28. Lesson 3: CSS Positioning Relative Positioning A relative positioned element is positioned relative to its normal position. Example h2.pos_left { position:relative; left:-20px; } h2.pos_right { position:relative; left:20px; } Try it yourself » The content of relatively positioned elements can be moved and overlap other elements, but the reserved space for the element is still preserved in the normal flow. Example h2.pos_top { position:relative; top:-50px; } Try it yourself » Relatively positioned elements are often used as container blocks for absolutely positioned elements. Source: http://www.w3schools.com/Css/css_positioning.asp
  • 29. Lesson 3: CSS Positioning Absolute Positioning An absolute position element is positioned relative to the first parent element that has a position other than static. If no such element is found, the containing block is <html>: Example h2 { position:absolute; left:100px; top:150px; } Try it yourself » Absolutely positioned elements are removed from the normal flow. The document and other elements behave like the absolutely positioned element does not exist. Absolutely positioned elements can overlap other elements. Source: http://www.w3schools.com/Css/css_positioning.asp
  • 30. Lesson 3: CSS Positioning Overlapping Elements When elements are positioned outside the normal flow, they can overlap other elements. The z-index property specifies the stack order of an element (which element should be placed in front of, or behind, the others). An element can have a positive or negative stack order: Example img { position:absolute; left:0px; top:0px; z-index:-1 } Try it yourself » An element with greater stack order is always in front of an element with a lower stack order. Note: If two positioned elements overlap, without a z-index specified, the element positioned last in the HTML code will be shown on top. Source: http://www.w3schools.com/Css/css_positioning.asp
  • 31. Lesson 3 Assignment: CSS Positioning Open A New Notepad Document Create an external CSS style sheet & a HTML Document with 4 div tags in HTML and 4 different styles in the external CSS that demonstrate CSS position. See example. You can use the examples at the following link as a guide: http://www.w3schools.com/Css/css_positioning.asp to create your document. CSS Style Example: div { left:0px; top:0px; z-index:-1 } HTML Example: <div> This box is positioned relative </div> Save Your Files as style.css and css-position.html in the same folder
  • 32. Lesson 4: Aligning Block Elements
  • 33. Lesson 4: Aligning Block Elements In CSS, several properties are used to align elements horizontally. Center Aligning Using the margin Property Block elements can be aligned by setting the left and right margins to &quot;auto&quot;. Note: Using margin:auto will not work in IE 8 and earlier, unless a !DOCTYPE is declared.
  • 34. Lesson 4: Aligning Block Elements Setting the left and right margins to auto specifies that they should split the available margin equally. The result is a centered element: Example .center { margin-left:auto; margin-right:auto; width:70%; background-color:#b0e0e6; } Try it yourself » Tip: Aligning has no effect if the width is 100%. Note: In IE 5 there is a margin handling bug for block elements. To make the example above work in IE5, add some extra code. Try it yourself Source: http://www.w3schools.com/css/css_align.asp
  • 35. Lesson 4: Aligning Block Elements Crossbrowser Compatibility Issues When aligning elements like this, it is always a good idea to predefine margin and padding for the <body> element. This is to avoid visual differences in different browsers. There is also another problem with IE when using the position property. If a container element (in our case <div class=&quot;container&quot;>) has a specified width, and the !DOCTYPE declaration is missing, IE will add a 17px margin on the right side. This seems to be space reserved for a scrollbar. Always set the !DOCTYPE declaration when using the position property. Source: http://www.w3schools.com/css/css_align.asp
  • 36. Lesson 4: Aligning Block Elements Example body { margin:0; padding:0; } .container { position:relative; width:100%; } .right { position:absolute; right:0px; width:300px; background-color:#b0e0e6; } Try it yourself » Source: http://www.w3schools.com/css/css_align.asp
  • 37. Lesson 4: Aligning Block Elements Left and Right Aligning Using the float Property One method of aligning elements is to use the float property: Example .right { float:right; width:300px; background-color:#b0e0e6; } Try it yourself »
  • 38. Lesson 4: Aligning Block Elements Cross browser Compatibility Issues When aligning elements like this, it is always a good idea to predefine margin and padding for the <body> element. This is to avoid visual differences in different browsers. There is also another problem with IE when using the float property. If the !DOCTYPE declaration is missing, IE will add a 17px margin on the right side. This seems to be space reserved for a scrollbar. Always set the !DOCTYPE declaration when using the float property
  • 39. Lesson 4: Aligning Block Elements Example body { margin:0; padding:0; } .right { float:right; width:300px; background-color:#b0e0e6; } Try it yourself »
  • 40. Lesson 5: Float
  • 41. Lesson 5: Float With CSS float, an element can be pushed to the left or right, allowing other elements to wrap around it. Float is very often used for images, but it is also useful when working with layouts. Source: http://w3schools.com/css/css_float.asp
  • 42. Lesson 5: How Elements Float Elements are floated horizontally, this means that an element 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. Usually this means all the way to the left or right of the containing element. The elements after the floating element will flow around it. The elements before the floating element will not be affected. If an image is floated to the right, a following text flows around it, to the left: Example img { float:right; } Try it yourself » Source: http://w3schools.com/css/css_float.asp
  • 43. Lesson 5: Float Floating Elements Next to Each Other If you place several floating elements after each other, they will float next to each other if there is room. Here we have made an image gallery using the float property: Example .thumbnail { float:left; width:110px; height:90px; margin:5px; } Try it yourself » Source: http://w3schools.com/css/css_float.asp
  • 44. Lesson 5: Float Turning off Float - Using Clear Elements after the floating element will flow around it. To avoid this, use the clear property. The clear property specifies which sides of an element other floating elements are not allowed. Add a text line into the image gallery, using the clear property: Example .text_line { clear:both; } Try it yourself » Source: http://w3schools.com/css/css_float.asp
  • 45. Lesson 5 Assignment: CSS Align and Float Open A New Notepad Document Create an external CSS style sheet & a HTML Document with 6 div tags in HTML and 4 different styles in the external CSS that demonstrate CSS align and float. See example. You can use the examples at the following link as a guide: 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 folder
  • 46. Lesson 6: Lists
  • 47. Lesson 6: Lists The CSS list properties allow you to: Set different list item markers for ordered lists Set different list item markers for unordered lists Set an image as the list item marker Source: http://w3schools.com/css/css_list.asp
  • 48. Lesson 6: Lists In HTML, there are two types of lists: unordered lists - the list items are marked with bullets ordered lists - the list items are marked with numbers or letters What is the tag in HTML that sets up an ordered list? What is the tag in HTML that sets up an unordered list? With CSS, lists can be styled further, and images can be used as the list item marker. Source: http://w3schools.com/css/css_list.asp
  • 49. Lesson 6: Different List Item Markers The type of list item marker is specified with the list-style-type property: Example ul.a {list-style-type: circle;} ul.b {list-style-type: square;} ol.c {list-style-type: upper-roman;} ol.d {list-style-type: lower-alpha;} Try it yourself » Source: http://w3schools.com/css/css_list.asp
  • 50. Lesson 6 Assignment: CSS Lists Unordered Create a web page with multiple unordered CSS list types. Values for Unordered Lists none = no marker disc circle square
  • 51. Lesson 6 Assignment: CSS Lists Ordered Create an HTML web page with 2 ordered and 2 unordered CSS list types in an external style sheet. See Example. Values for Ordered Lists Examples: Armenian = The marker is traditional Armenian numbering Decimal = The marker is a number decimal-leading-zero = The marker is a number padded by initial zeros (01, 02, 03, etc.) Georgian = The marker is traditional Georgian numbering (an, ban, gan, etc.) lower-alpha = The marker is lower-alpha (a, b, c, d, e, etc.) lower-greek = The marker is lower-greek (alpha, beta, gamma, 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.) 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-roman = The marker is upper-roman (I, II, III, IV, V, etc.)
  • 52. Lesson 6: Lists Using Images An Image as The List Item Marker To specify an image as the list item marker, use the list-style-image property: Example ul { list-style-image: url('sqpurple.gif'); } Try it yourself » The example above does not display equally in all browsers. IE and Opera will display the image-marker a little bit higher than Firefox, Chrome, and Safari. More list examples: http://w3schools.com/css/tryit.asp?filename= trycss_list-style-type_all
  • 53. Lesson 6 Assignment: CSS Lists With An Image Open your css-lists.html web page in notepad add 2 list types in the external style sheet that have pictures as bullets. See Example. You can download a royalty free picture from use as a bullet.
  • 54. Lesson 7: Fonts & Text On Web Pages
  • 55. Lesson 7: Points are For Print Many Web designers have gotten into the bad habit of using point sizes to define their font sizes on the screen. But points are a print unit of measure, and the Web is usually viewed on the screen. This means that when you specify 14-point type, it might display much larger or smaller than you expect. The most common place this is noticed is between Macintosh and Windows. Macintosh typically displays things almost 25% smaller than the same page on Windows. The next few slides will explain how to adjust fonts to work well on web pages.
  • 56. Lesson 7: Setting Font Size Font Size The font-size property sets the size of the text. Being able to manage the text size is important in web design. However, you should not use font size adjustments to make paragraphs look like headings, or headings look like paragraphs. Always use the proper HTML tags, like <h1> - <h6> for headings and <p> for paragraphs. The font-size value can be an absolute, or relative size.
  • 57. Absolute size: Sets the text to a specified size Does not allow a user to change the text size in all browsers (bad for accessibility reasons) Absolute size is useful when the physical size of the output is known Lesson 7: Setting Font Size
  • 58. Relative size: Sets the size relative to surrounding elements Allows a user to change the text size in browsers If you do not specify a font size, the default size for normal text, like paragraphs, is 16px (16px=1em). Lesson 7: Setting Font Size
  • 59. Lesson 7: Setting Font Size with Pixels Set Font Size With Pixels Setting the text size with pixels, gives you full control over the text size: Example h1 {font-size:40px;} h2 {font-size:30px;} p {font-size:14px;} 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).
  • 60. Lesson 7: Setting Font Size with Em Set Font Size With Em To avoid the resizing problem with Internet Explorer, many developers use em instead of pixels. The em size unit is recommended by the W3C. 1em is equal to the current font size. The default text size in browsers is 16px. So, the default size of 1em is 16px. The size can be calculated from pixels to em using this formula: pixels /16= em Example h1 {font-size:2.5em;} /* 40px/16=2.5em */ h2 {font-size:1.875em;} /* 30px/16=1.875em */ p {font-size:0.875em;} /* 14px/16=0.875em */ Try it yourself » 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 the text size in all browsers. 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 should when made smaller.
  • 61. Lesson 7: Setting Font Size with Em Use a Combination of Percent and Em The solution that works in all browsers, is to set a default font-size in percent for the body element: Example body {font-size:100%;} h1 {font-size:2.5em;} h2 {font-size:1.875em;} p {font-size:0.875em;} Try it yourself » Our code now works great! It shows the same text size in all browsers, and allows all browsers to zoom or resize the text!
  • 62. Lesson 7: Font Style The font-style property is mostly used to specify italic text. This property has three values: normal - The text is shown normally italic - The text is shown in italics oblique - The text is &quot;leaning&quot; (oblique is very similar to italic, but less supported) Example p.normal {font-style:normal;} p.italic {font-style:italic;} p.oblique {font-style:oblique;} h1 {font-style: italic} h2 {font-style: normal} p {font-style: oblique} Try it yourself »
  • 63. Lesson 7: CSS Font Families In CSS, there are two types of font family names: generic family - a group of font families with a similar look (like &quot;Serif&quot; or &quot;Monospace&quot;) font family - a specific font family (like &quot;Times New Roman&quot; or &quot;Arial&quot;) Generic family Serif (Times New Roman, Georgia) Serif fonts have small lines at the ends on some characters Sans-serif (Arial, Verdana) &quot;Sans&quot; means without - these fonts do not have the lines at the ends of characters Monospace (Courier, New Lucida, Console) All monospace characters have the same width
  • 64. Lesson 7: CSS Font Families The font family of a text is set with the font-family property. The font-family property should hold several font names as a &quot;fallback&quot; system. If the browser does not support the first font, it tries the next font. 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 other fonts are available. Note : If the name of a font family is more than one word, it must be in quotation marks, like font-family: &quot;Times New Roman&quot;. More than one font family is specified in a comma-separated list Example p{font-family:&quot;Times New Roman&quot;, Times, serif;} Try it yourself »
  • 65. Lesson 7: Font Bold Examples to specify bold by thickness: p.normal {font-weight: normal} p.thick {font-weight: bold} p.thicker {font-weight: 900}
  • 66. Lesson 7: Setting all the Styles in one line for FONT Shortcut Example: p { font: italic small-caps 900 12px arial }
  • 67. Lesson 7: Text Color The color property is used to set the color of the text. The color can be specified by: name - a color name, like &quot;red&quot; RGB - an RGB value, like &quot;rgb(255,0,0)&quot; Hex - a hex value, like &quot;#ff0000&quot; The default color for a page is defined in the body selector. Example body {color:blue;} h1 {color:#00ff00;} h2 {color:rgb(255,0,0);} Try it yourself » For W3C compliant CSS: If you define the color property, you must also define the background-color property.
  • 68. Lesson 7: Text Alignment The text-align property is used to set the horizontal alignment of a text. Text can be centered, or aligned to the left or right, or justified. When text-align is set to &quot;justify&quot;, each line is stretched so that every line has equal width, and the left and right margins are straight (like in magazines and newspapers). Example h1 {text-align:center;} p.date {text-align:right;} p.main {text-align:justify;} Try it yourself »
  • 69. Lesson 7: Text Decoration The text-decoration property is used to set or remove decorations from text. The text-decoration property is mostly used to remove underlines from links for design purposes Example a {text-decoration:none;} Try it yourself » It can also be used to decorate text Example h1 {text-decoration:overline;} h2 {text-decoration:line-through;} h3 {text-decoration:underline;} h4 {text-decoration:blink;} Try it yourself » It is not recommended to underline text that is not a link, as this often confuses users.
  • 70. Lesson 7: Text Transformation The text-transform property is used to specify uppercase and lowercase letters in a text. It can be used to turn everything into uppercase or lowercase letters, or capitalize the first letter of each word. Example p.uppercase {text-transform:uppercase;} p.lowercase {text-transform:lowercase;} p.capitalize {text-transform:capitalize;} Try it yourself »
  • 71. Lesson 7: Text Indentation The text-indentation property is used to specify the indentation of the first line of a text. Example p {text-indent:50px;} Try it yourself »
  • 72. Lesson 7 Assignment: CSS Fonts & Text Create a new external notepad CSS style sheet and an HTML document that shows 10 paragraphs with different examples of formatting text. Save Your File as css-fonts.html and your style sheet into your folder.
  • 73. Lesson 8: CSS Tables
  • 74. Lesson 8: HTML Tables Review Tables are defined with the <table> tag. A table is divided into rows (with the <tr> tag), each row is divided into data cells (with the <td> tag). td stands for &quot;table data,&quot; and holds the content of a data cell. A <td> tag can contain text, links, images, lists, forms, other tables, etc.
  • 75. Lesson 8: HTML Tables Review Table Example <table border=&quot;1&quot;> <tr> <td>row 1, cell 1</td> <td>row 1, cell 2</td> </tr> <tr> <td>row 2, cell 1</td> <td>row 2, cell 2</td> </tr> </table>
  • 76. Lesson 8: CSS Table Borders The look of an HTML table can be greatly improved with CSS Table Borders To specify table borders in CSS, use the border property. The example below specifies a black border for table, th, and td elements: Example table, th, td { border: 1px solid black; } Try it yourself »
  • 77. Lesson 8: Table Width and Height Width and height of a table is defined by the width and height properties. The example below sets the width of the table to 100%, and the height of the th elements to 50px: Example table { width:100%; } th { height:50px; } Try it yourself »
  • 78. Lesson 8: Table Text Alignment The text in a table is aligned with the text-align and vertical-align properties. The text-align property sets the horizontal alignment, like left, right, or center: Example td { text-align:right; } Try it yourself » The vertical-align property sets the vertical alignment, like top, bottom, or middle: Example td { height:50px; vertical-align:bottom; } Try it yourself »
  • 79. Lesson 8: Table Padding To control the space between the border and content in a table, use the padding property on td and th elements: Example td { padding:15px; } Try it yourself »
  • 80. Lesson 8: Table Color The example below specifies the color of the borders, and the text and background color of th elements: Example table, td, th { border:1px solid green; } th { background-color:green; color:white; } Try it yourself »
  • 81. Lesson 8 Assignment: CSS Table Create a new external notepad CSS style sheet and an HTML document that shows a table with 5 rows and 3 columns with different examples of formatting text inside of it. Save Your File as css-table.html and your style sheet into your folder.
  • 82. Lesson 9: White Space & Borders
  • 83. Lesson 9: White Space In web pages white space will allow you to define the look and feel of a web page by providing white area around elements. Let’s take a look at some pages that make good use of white space. http://online.wsj.com/home-page http://www.csszengarden.com/?cssfile=/206/206.css&page=0 http:// www.csszengarden.com/?cssfile =/210/210.css&page=0
  • 84. Lesson 9: Borders CSS Border Properties The CSS border properties allow you to specify the style and color of an element's border. Border Style The border-style property specifies what kind of border to display. None of the border properties will have ANY effect unless the border-style property is set!
  • 85. Lesson 9: Border-style values: none: Defines no border dotted: Defines a dotted border dashed: Defines a dashed border solid: Defines a solid border double: Defines two borders. The width of the two borders are the same as the border-width value groove: Defines a 3D grooved border. The effect depends on the border-color value ridge: Defines a 3D ridged border. The effect depends on the border-color value inset: Defines a 3D inset border. The effect depends on the border-color value outset: Defines a 3D outset border. The effect depends on the border-color value
  • 86. Lesson 9: Border Width The border-width property is used to set the width of the border. The width is set in pixels, or by using one of the three pre-defined values: thin, medium, or thick. Note: The &quot;border-width&quot; property does not work if it is used alone. Use the &quot;border-style&quot; property to set the borders first. Example p.one { border-style:solid; border-width:5px; } p.two { border-style:solid; border-width:medium; } Try it yourself »
  • 87. Lesson 9: Border Color The border-color property is used to set the color of the border. The color can be set by: name - specify a color name, like &quot;red&quot; RGB - specify a RGB value, like &quot;rgb(255,0,0)&quot; Hex - specify a hex value, like &quot;#ff0000&quot; You can also set the border color to &quot;transparent&quot;. Note: The &quot;border-color&quot; property does not work if it is used alone. Use the &quot;border-style&quot; property to set the borders first. Example p.one { border-style:solid; border-color:red; } p.two { border-style:solid; border-color:#98bf21; } Try it yourself »
  • 88. Lesson 9: Border - Individual sides In CSS it is possible to specify different borders for different sides Example p { border-top-style:dotted; border-right-style:solid; border-bottom-style:dotted; border-left-style:solid; } Try it yourself » The example above can also be set with a single property Example border-style:dotted solid; Try it yourself »
  • 89. Lesson 9: Border - Shorthand property As you can see from the examples above, there are many properties to consider when dealing with borders. To shorten the code, it is also possible to specify all the border properties in one property. This is called a shorthand property. The shorthand property for the border properties is &quot;border&quot;: Example border:5px solid red; Try it yourself » When using the border property, the order of the values are: border-width border-style border-color 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 order.
  • 90. Lesson 9: White Space - Margins The CSS margin properties define the space (white space) around elements. The 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. Possible Values Auto - The browser sets the margin. The result of this is dependant of the browser Length - Defines a fixed margin (in pixels, pt, em, etc.) % - Defines a margin in % of the containing element. It is possible to use negative values, to overlap content.
  • 91. Lesson 9: White Space - Margins The margin property can have from one to four values. margin:25px 50px 75px 100px; top margin is 25px right margin is 50px bottom margin is 75px left margin is 100px margin:25px 50px 75px; top margin is 25px right and left margins are 50px bottom margin is 75px margin:25px 50px; top and bottom margins are 25px right and left margins are 50px margin:25px; all four margins are 25px
  • 92. Lesson 9: White Space - Margins Margin - Shorthand property To shorten the code, it is possible to specify all the margin properties in one property. This is called a shorthand property. The shorthand property for all the margin properties is &quot;margin&quot;: Example margin:100px 50px; Try it yourself »
  • 93. Lesson 9: White Space - Margins Margin - Individual sides In CSS, it is possible to specify different margins for different sides: Example margin-top:100px; margin-bottom:100px; margin-right:50px; margin-left:50px; Try it yourself »
  • 94. Lesson 9: White Space - Padding The CSS padding properties define the space between the element border and the element content. The padding clears an area around the content (inside the border) of an element. The padding is affected by the background color of the element. The top, right, bottom, and left padding can be changed independently using separate properties. A shorthand padding property can also be used, to change all paddings at once. Possible Values Length - Defines a fixed padding (in pixels, pt, em, etc.) % - Defines a padding in % of the containing element
  • 95. Lesson 9: White Space - Padding Padding - Individual sides In CSS, it is possible to specify different padding for different sides: Example padding-top:25px; padding-bottom:25px; padding-right:50px; padding-left:50px; Try it yourself »
  • 96. Lesson 9: White Space - Padding Padding - Shorthand property To shorten the code, it is possible to specify all the padding properties in one property. This is called a shorthand property. The shorthand property for all the padding properties is &quot;padding&quot;:
  • 97. Lesson 9: White Space - Padding Padding - Individual sides In CSS, it is possible to specify different padding for different sides: Example padding-top:25px; padding-bottom:25px; padding-right:50px; padding-left:50px; Try it yourself »
  • 98. Lesson 9: White Space - Padding The padding property can have from one to four values. padding:25px 50px 75px 100px; top padding is 25px right padding is 50px bottom padding is 75px left padding is 100px padding:25px 50px 75px; top padding is 25px right and left paddings are 50px bottom padding is 75px padding:25px 50px; top and bottom paddings are 25px right and left paddings are 50px padding:25px; all four paddings are 25px
  • 99. Lesson 9 Assignment: CSS White Space Create a new external notepad CSS style sheet and an HTML document that shows a 4 div tags with 5 examples of white space. Save Your File as css-whitespace.html and your style sheet into your folder.
  • 100. Lesson 10: Navigation Menus
  • 101. Lesson 10: Navigation Menus Navigation Bars Having easy-to-use navigation is important for any web site. With CSS you can transform boring HTML menus into good-looking navigation bars. Navigation Bar = List of Links A navigation bar needs standard HTML as a base. In our examples we will build the navigation bar from a standard HTML list.
  • 102. Lesson 10: Navigation Menus A navigation bar is basically a list of links, so using the <ul> and <li> elements makes perfect sense: Example <ul> <li><a href=&quot;default.asp&quot;>Home</a></li> <li><a href=&quot;news.asp&quot;>News</a></li> <li><a href=&quot;contact.asp&quot;>Contact</a></li> <li><a href=&quot;about.asp&quot;>About</a></li> </ul> Try it yourself »
  • 103. Lesson 10: Navigation Menus Now let's remove the bullets and the margins and padding from the list: Example ul { list-style-type:none; margin:0; padding:0; } Try it yourself »
  • 104. Lesson 10: Vertical Navigation Menus To build a vertical navigation bar we only need to style the <a> elements, in addition to the code above: Example a { display:block; width:60px; } Try it yourself » Example explained: 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 width:60px - Block elements take up the full width available by default. We want to specify a 60 px width
  • 105. Lesson 10: Horizontal Navigation Menus There are two ways to create a horizontal navigation bar. Using inline or floating list items. Both methods work fine, but if you want the links to be the same size, you have to use the floating method. Inline List Items One way to build a horizontal navigation bar is to specify the <li> elements as inline, in addition to the &quot;standard&quot; code above: Example li { display:inline; } Try it yourself » Example explained: display:inline; - By default, <li> elements are block elements. Here, we remove the line breaks before and after each list item, to display them on one line
  • 106. Lesson 10: Navigation Menus Floating List Items In the example above the links have different widths. For all the links to have an equal width, float the <li> elements and specify a width for the <a> elements Example li { float:left; } a { display:block; width:60px; } Try it yourself » Example explained: 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 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 float next to each other. We specify the width of the links to 60px
  • 107. Lesson 10 Assignment: CSS Navigation Menus Create a new external notepad CSS style sheet and an HTML document that shows a 1 example of a vertical navigation bar and 1 horizontal navigation bar each with 4 buttons. Save Your File as css-navigationbar.html and your style sheet into your folder.
  • 108. Culminating Unit Performance Task Daily News Web Page
  • 110. CSS 3 CSS is used to control the style and layout of Web pages. CSS3 is the latest standard for CSS.
  • 111. CSS3 Example div { transform:rotate(30deg); } Try it yourself » Works on Chrome and Firefox not IE. CSS3 Reference table: http://w3schools.com/css3/css3_reference.asp