1 / 15

Cascading Style Sheets

Cascading Style Sheets. Controlling the Display Of Web Content. Why use style sheets. Separate structure from presentation HTML files less complex One style sheet for an entire site keeps the styling consistent across different pages Different users can have different style sheets

Download Presentation

Cascading Style Sheets

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Cascading Style Sheets Controlling the Display Of Web Content

  2. Why use style sheets • Separate structure from presentation • HTML files less complex • One style sheet for an entire site keeps the styling consistent across different pages • Different users can have different style sheets • Can have different style sheets for different media (print vs. screen e.g.)

  3. CSS Style Sheets • Style sheets are used to specify the presentation style of a web document. • Cascading Style Sheet (CSS) is a language for specifying presentation style • Overseen by W3C • http://www.w3.org

  4. Components of CSS • Style declarations • property : value • Selectors determine which properties are assigned to different HTML elements • Inheritance and cascading rules control what properties affect child elements

  5. Style Rule selector { property1 : value1; property2 : value2; … propertyn : valuen } h1 {font-size: large; color : #009 }

  6. Where do the rules go? • Separate file (with .css extension) • Use <link> element to attach style sheet to html file <link rel="stylesheet" type="text/css" href="myStyle.css" /> • In a <style type="text/css> element in the <head> of the HTML document

  7. <html><head> <link rel="stylesheet" type="text/css" href="style.css"> </head><body> <h2>… </h2> <h2>… </h2> </body></html> in style.css … h2 { font-size: 150% } … Attached Style Sheet

  8. Style Element <html><head> <style type="text/css"> body { font-size: small } h1 {font-size: large; color: #009 } </style> </head><body> <h2>… </h2> </body></html>

  9. Selectors • Element: comma-separated list of tag names • can use * to select all elements • Class: tag.classname to select all elements with class=classname • Attribute: tag[attr] or tag[attr="value"] to select elements with a particular attribute or attribute value

  10. More selectors • Id : #idName to select elements with particular id attribute • Contextual: a img • Pseudoclass: :link :active :visited :hover • Pseudoelement: p:first-letter p:first-line

  11. Properties • background - color, image (with position and repeat) • text - color, background color, spacing, alignment, decoration, indentation • borders - color, style, width • font - size, style • margins and padding - each side independently if desired • lists - markers

  12. Margin, Border, Padding • Block boxes • Inline boxes

  13. Sources • Web Design and Programming by Paul S. Wang and Sanda S. Katila • Wikipedia • http://en.wikipedia.org/wiki/Cascading_Style_Sheets • W3 Schools • http://www.w3schools.com/css/default.asp • Complete CSS Guide (online version) • http://www.westciv.com/style_master/academy/css_tutorial/index.html

  14. favicons • Make a custom icon that shows up in the title bar of the browser and in the bookmark list. • Create a 16x16 bit image file • acceptable formats: gif, png, the windows ico • Put it in your public_html directory • Add link element(s) to the head element • <link rel="shortcut icon" href="images/lwp.ico" type="image/x-icon" /> • <link rel="icon" href="images/lwp.ico" type="image/x-icon" />

  15. How to make an ico image • Create a 16x16 image that you can open with gimp (or create it in gimp if you know how) • From gimp, do save as with a .ppm extension • do ppmtowinicon -output image.ico image.ppm

More Related