Successfully reported this slideshow.
Your SlideShare is downloading. ×
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Upcoming SlideShare
Introduction to CSS
Introduction to CSS
Loading in …3
×

Check these out next

1 of 40 Ad

CSS Basics

Download to read offline

Presentation to WordPress Memphis meetup group on December 2, 2010, CSS Basics. By designer Irina McGuire.

http://www.irinamcguire.com

Presentation to WordPress Memphis meetup group on December 2, 2010, CSS Basics. By designer Irina McGuire.

http://www.irinamcguire.com

Advertisement
Advertisement

More Related Content

Slideshows for you (20)

Advertisement

Recently uploaded (20)

CSS Basics

  1. 1. The Basics of Cascading Style Sheets (CSS) Irina McGuire Graphic Designer | Front-End Web Developer www.irinamcguire.com December 3, 2010
  2. 2. Introduction <ul><li>What do you know about CSS? </li></ul><ul><li>What do you hope to do with CSS? </li></ul><ul><li>How familiar are you with HTML? </li></ul>Examples of beautiful CSS Web sites: www.csszengarden.com One content, many layouts .
  3. 3. Presentation Summary <ul><li>What is CSS? </li></ul><ul><li>CSS & HTML </li></ul><ul><li>The Box Model </li></ul><ul><li>Style Sheet Implementation </li></ul><ul><li>CSS Rule Structure </li></ul><ul><li>HTML & DIVs </li></ul><ul><li>Common CSS properties </li></ul><ul><li>CSS Cascade and Inheritance </li></ul><ul><li>Resources </li></ul>
  4. 4. What is CSS? CSS stands for Cascading Style Sheet . Typical CSS file is a text file with an extention .css and contains a series of commands or rules. These rules tell the HTML how to display. *To create a style sheet, create a file using Notepad (PC) or Text Edit (Mac), save it as a .css document and start writing the CSS code (see right). /* Styles for sitename.com*/ body { font-family:Arial; background: #000; } #container { text-align:left; width:1020px; } #header { height:232px; } #footer { width: 100%; padding: 0 10px; margin-bottom: 10px; } And so on…. Style.css
  5. 5. CSS Benefits <ul><li>Separates structure from presentation </li></ul><ul><li>Provides advanced control of presentation </li></ul><ul><li>Easy maintenance of multiple pages </li></ul><ul><li>Faster page loading </li></ul><ul><li>Better accessibility for disabled users </li></ul><ul><li>Easy to learn </li></ul>
  6. 6. HTML Without CSS “ HTML without CSS is like a piece of candy without a pretty wrapper.” Without CSS, HTML elements typically flow from top to bottom of the page and position themselves to the left by default. With CSS help, we can create containers or DIVs to better organize content and make a Web page visually appealing.
  7. 7. HTML & CSS <ul><li>HTML and CSS work together to produce beautiful and functional Web sites </li></ul><ul><li>HTML = structure </li></ul><ul><li>CSS = style </li></ul>
  8. 8. The Box Model CSS works on the box model. A typical Web page consists of many boxes joined together from top to bottom. These boxes can be stacked, nested, and can float. Header Navigation Content Footer
  9. 9. Attaching a Style Sheet <ul><li>Attach a style sheet to a page by adding the code to the <head> section of the HTML page. There are 3 ways to attach CSS to a page: </li></ul><ul><li>1. External Style Sheet: Best used to control styling on multiple pages. </li></ul><ul><li><link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; media=&quot;all&quot; href=&quot;css/styles.css&quot; /> </li></ul><ul><li>2. Internal Style Sheet: Best used to control styling on one page. </li></ul><ul><ul><ul><li><style type=“text/css”> h1 {color: red) </style> </li></ul></ul></ul><ul><li>3. Inline Style Sheet*: CSS is not attached in the <header> but is used directly within HTML tags. </li></ul><ul><li><p style=“color: red” >Some Text</p> </li></ul>
  10. 10. CSS Rule Structure A CSS RULE is made up of a selector and a declaration. A declaration consists of property and value. selector { property: value; } declaration
  11. 11. Selectors body { property : value ; } h1 { property : value ; } em { property : value ; } p { property : value ; } A selector, here in green , is often an element of HTML.
  12. 12. Properties and Values body { background: purple; } h1 { color: green; } h2 { font-size: large; } p { color: #ff0000;} /*hexadecimal for red*/ body { background: purple; color: green; } Properties and values tell an HTML element how to display. *CSS code can be written in a linear format (above) or in a block format (below).
  13. 13. Grouping Selectors h1 {color: black;} h1 {font-weight: bold;} h1 {background: white;} h1 { color: black; font-weight: bold; background: white; } Group the same selector with different declarations together on one line. Example of grouping selectors (both are correct):
  14. 14. Grouping Selectors Group different selectors with the same declaration on one line. h1 { color: yellow; } h2 { color: yellow; } h3 { color: yellow; } h1, h2, h3 { color: yellow; } Example of grouping selectors (both are correct):
  15. 15. Comments in CSS <ul><li>Explain the purpose of the coding </li></ul><ul><li>Help others read and understand the code </li></ul><ul><li>Serve as a reminder to you for what it all means </li></ul><ul><li>Starts with /*and ends with*/ </li></ul>p { color: #ff0000;} /*Company Branding*/
  16. 16. Typical Web Page (Browser) header footer main menu Container
  17. 17. Typical Web Page (HTML) <div id=“ container ”> <div id=“ header ”>Insert Title</div> <div id=“ main &quot;>content <div id=“ menu ”>content</div> </div> <div id=“ footer ”>content</div> </div> Typical HTML Web page is made up of containers (boxes) or DIVs. Each DIV is assigned an ID or a Class.
  18. 18. Typical Web Page (CSS) # container {property: value;} # menu {property: value;} # main {property: value;} # footer {property: value;} The CSS file uses the same DIV/ID/Class names as the HTML and uses them to style the elements.
  19. 19. IDs and Classes <ul><li>IDs (#) are unique and can only be used once on the page </li></ul><ul><li>Classes (.) can be used as many times as needed </li></ul><ul><li>HTML Code: </li></ul><ul><li><h1 id=“ mainHeading ”>Names</h1> </li></ul><ul><li><p class=“ name ”>Joe</p> </li></ul><ul><li>CSS Code: </li></ul><ul><li># mainHeading {color: green} </li></ul><ul><li>. name {color: red} </li></ul>
  20. 20. CSS Box Properties <ul><li>Background-color </li></ul><ul><li>Width </li></ul><ul><li>Padding </li></ul><ul><li>Margin </li></ul><ul><li>Border-width </li></ul><ul><li>Border-color </li></ul><ul><li>Border-style </li></ul>
  21. 21. HTML CSS div id=“header” div id=“footer” div id=“content” # content { background-color: #ccc; margin-bottom: 10px; border: 1px dashed blue; color: #fff; width: auto; }
  22. 22. Common CSS Layout Properties <ul><li>Width </li></ul><ul><li>Height </li></ul><ul><li>Float </li></ul><ul><li>Clear </li></ul><ul><li>Border </li></ul><ul><li>Padding </li></ul><ul><li>Margin </li></ul>width height padding margin border
  23. 23. Width & Height div id=“box” #box {width=“50px”} #box {width=“50em”} #box {width=“100%”} #box {width=“auto”} Width and height define the width and height of an element. #box {height=“auto”} *Width and height can be specified in pixels, ems, percentages or set to auto
  24. 24. Float: (left, right) Float property makes elements float to the right or left of the screen, positioned where they are in the HTML. Floating allows word wrapping. div id=“box” Here is some text which wraps around the box floated to the left. #box {float:left; margin-right: 10px;}
  25. 25. Clear: (left, right, both) #box3 { background-color: white; border: 1px solid #000; clear: both;} When elements are floated, they wrap around each other to form a “caravan.” The clear property detaches an element from the “caravan” and allows it to start on a new line. div id=“box1” div id=“box2” div id=“box3”
  26. 26. Border (top, right, bottom, left) #box { border-color: red; border-style: dotted; border-width: 2px; div id=“box” #box { border: red dotted 1px; #box { border-top: red dotted 1px; border-bottom: red dotted 1px; border-left: red dotted 1px; border-right: red dotted 1px; } You can define the entire border or only the top, bottom, left, or right. You can also define the border using one declaration. The code could be any of the following:
  27. 27. Padding (top, right, bottom, left) Padding is the space between the text/content and the border. You can use padding for all around the element or specify each side of the rectangle separately. The code could be any of the following: padding: 10px; Padding: 10px 10px; padding: 10px 10px 10px 10px; padding-left: 10px; padding-right: 10px; padding-bottom: 10px; padding-top: 10px; div id=“box” padding
  28. 28. Margin (top, right, bottom, left) Margin is the space outside the text/content and the border. You can use margin for all around the element or specify each side of the rectangle separately. The code could be any of the following: margin: 10px; or margin: 10px 10px; or margin: 10px 10px 10px 10px; or margin-left: 10px; margin-right: 10px; margin-bottom: 10px; margin-top: 10px; margin div id=“box”
  29. 29. Text Properties .mainHeading { color: red; letter-spacing: 5px; text-transform: uppercase; word-spacing: 15px; text-align: left; font-family: Times; text-decoration: underline; font-size: 12px; font-style: italic; font-weight: bold; } MAIN HEADING Gravida lacinia velit. Vivamus tortor enim, tincidunt at, pellentesque ut, iaculis eu, quam. To style the main heading in the paragraph above, we assigned a class the HTML tag. <h3 class=“mainHeading”>Main Heading</h3>
  30. 30. CSS Colors <ul><li>White </li></ul><ul><li>Black </li></ul><ul><li>Blue </li></ul><ul><li>Fuchsia </li></ul><ul><li>Gray </li></ul><ul><li>Green </li></ul><ul><li>Lime </li></ul><ul><li>Aqua </li></ul><ul><li>#ffffff </li></ul><ul><li>#fff </li></ul><ul><li>#cccf0f3 </li></ul>Standard Hexadecimal
  31. 31. Styling Links a:link {color: red; text-decoration: none;border-bottom: 1px dashed red; background: white;} a:visited {color: yellow;} a:active {color: green;} a:hover {color: orange;} The links property defines how inactive, hovered, active, and visited link states appear to the user.
  32. 32. Including Images <ul><li>Properties for working with images include: </li></ul><ul><ul><li>Background-image </li></ul></ul><ul><ul><li>Background-repeat </li></ul></ul><ul><ul><li>Background-position </li></ul></ul><ul><ul><li>Background-attachment </li></ul></ul>
  33. 33. Layering Background colors and images are layered like sheets of paper one on top of the other. #bg { background:url(leaves.jpg) no-repeat top left} #main {background-color: red} #box {background-color: yellow} div id=“bg” div id=“main” div id=“box”
  34. 34. Background-Image li { background-image:url(flower.jpg); padding-left: 10px; } Background images and colors are layered. If not transparent, the last one listed in the CSS file is visible. The background-image property sets an image in the background of an element.
  35. 35. Background-Repeat li { background-image:url(flower.jpg); background-repeat:no-repeat; } Possible Values > The background-repeat property sets an image in the background of an element and tiles, or repeats, it. Tiling is the default. <ul><ul><li>repeat </li></ul></ul><ul><ul><li>repeat-x (horizontal) </li></ul></ul><ul><ul><li>repeat-y (vertical) </li></ul></ul><ul><ul><li>no-repeat </li></ul></ul>
  36. 36. Image Positioning The background-position property positions the image using either combined keywords (top, bottom, left, right, and center); length values; or percentage values. The background-attachment property fixes or scrolls an image in the browser window. Values include fixed and scroll . background-position: right top; /*can also use number values*/ background-attachment: fixed; /*can also use ‘scroll’*/ left top center top left bottom center bottom right bottom
  37. 37. The Power of Cascade <ul><li>When multiple styles or style sheets are used, they start to cascade and sometimes compete with one another due to CSS’s inheritance feature. Any tag on the page could potentially be affected by any of the tags surrounded by it. </li></ul><ul><li>So, which one wins? Nearest Ancestor Wins. </li></ul><ul><li>Inline style or directly applied style </li></ul><ul><li>The last style sheet declared in the <header> section </li></ul>
  38. 38. Saving Time with Inheritance In a nutshell, inheritance (not the money you get from your grandma) is the process by which CSS properties applied to one tag are passed on to nested tags. For example, the paragraph tag will inherit the same styling as the body tag because <p> is always located inside <body>. <body style=“font-family: Arial”> <p>This text will be Arial as well</p> </body> So, instead of styling each paragraph separately, you can define the font color in the <body>, and everything inside will have that color.
  39. 39. Resources <ul><li>http://www.w3schools.com/css/css_reference.asp (list of all CSS properties) </li></ul><ul><li>http://www.w3schools.com/css/ </li></ul><ul><li>http://www.glish.com/css/ </li></ul><ul><li>http://www.html.net/tutorials/css/ </li></ul><ul><li>http://blog.html.it/layoutgala/ </li></ul><ul><li>Great Book </li></ul><ul><li>“ CSS: The Missing Manual” - by David Sawyer McFarland </li></ul><ul><li>CSS Galleries </li></ul><ul><li>http://www.cssbeauty.com/gallery/ </li></ul><ul><li>www.cssdrive.com </li></ul><ul><li>http://www.css-website.com </li></ul>
  40. 40. Thank You I hope you enjoyed this presentation and learned some basic CSS. Good luck with creating beautiful and functional Web sites.

Editor's Notes

  • Cascading Style Sheets: Pixel-Level Control with HTML Ease
  • Cascading Style Sheets: Pixel-Level Control with HTML Ease
  • Cascading Style Sheets: Pixel-Level Control with HTML Ease
  • Cascading Style Sheets: Pixel-Level Control with HTML Ease
  • Cascading Style Sheets: Pixel-Level Control with HTML Ease
  • Cascading Style Sheets: Pixel-Level Control with HTML Ease
  • Cascading Style Sheets: Pixel-Level Control with HTML Ease
  • Cascading Style Sheets: Pixel-Level Control with HTML Ease
  • Cascading Style Sheets: Pixel-Level Control with HTML Ease
  • Cascading Style Sheets: Pixel-Level Control with HTML Ease
  • Cascading Style Sheets: Pixel-Level Control with HTML Ease
  • Cascading Style Sheets: Pixel-Level Control with HTML Ease
  • Cascading Style Sheets: Pixel-Level Control with HTML Ease
  • Cascading Style Sheets: Pixel-Level Control with HTML Ease
  • Cascading Style Sheets: Pixel-Level Control with HTML Ease
  • Cascading Style Sheets: Pixel-Level Control with HTML Ease
  • Cascading Style Sheets: Pixel-Level Control with HTML Ease
  • Cascading Style Sheets: Pixel-Level Control with HTML Ease
  • Cascading Style Sheets: Pixel-Level Control with HTML Ease
  • Cascading Style Sheets: Pixel-Level Control with HTML Ease
  • Cascading Style Sheets: Pixel-Level Control with HTML Ease
  • Cascading Style Sheets: Pixel-Level Control with HTML Ease
  • Cascading Style Sheets: Pixel-Level Control with HTML Ease
  • Cascading Style Sheets: Pixel-Level Control with HTML Ease
  • Cascading Style Sheets: Pixel-Level Control with HTML Ease
  • Cascading Style Sheets: Pixel-Level Control with HTML Ease
  • Cascading Style Sheets: Pixel-Level Control with HTML Ease
  • Cascading Style Sheets: Pixel-Level Control with HTML Ease
  • Cascading Style Sheets: Pixel-Level Control with HTML Ease
  • Cascading Style Sheets: Pixel-Level Control with HTML Ease
  • Cascading Style Sheets: Pixel-Level Control with HTML Ease
  • Cascading Style Sheets: Pixel-Level Control with HTML Ease
  • Cascading Style Sheets: Pixel-Level Control with HTML Ease
  • Cascading Style Sheets: Pixel-Level Control with HTML Ease
  • Cascading Style Sheets: Pixel-Level Control with HTML Ease
  • Cascading Style Sheets: Pixel-Level Control with HTML Ease
  • Cascading Style Sheets: Pixel-Level Control with HTML Ease
  • Cascading Style Sheets: Pixel-Level Control with HTML Ease
  • Cascading Style Sheets: Pixel-Level Control with HTML Ease
  • Cascading Style Sheets: Pixel-Level Control with HTML Ease

×