1 / 17

Cascading Style Sheets Part 1

Learn about the basics of HTML markup and CSS, including the separation of content and presentation, different types of style sheets, and the order of precedence for CSS styles.

Télécharger la présentation

Cascading Style Sheets Part 1

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 Part 1 Library and Information Services, University of St Andrews

  2. CSS vs HTML • HTML: • Originally intended to markup structure of a document (<h1>, <h2> ... <h6>, <p>, <ol>, <ul>, <blockquote>, ...) • CSS • Developing technology, CSS1, CSS2 (CSS3 under discussion) • Markup presentation, i.e. formats and layout  Separation of content and presentation

  3. CSS Structure selector {property: value;} • Selector: • on a simple level HTML element you wish to define • Property: • attribute you wish to change • Value: • value the property takes

  4. Internal Style Sheets (1/2) • Inline • Affects individual HTML tag <html> ... <body> ... <p style=“font-family: Arial, sans- serif; ”>some text</p> </body> </html>

  5. Internal Style Sheets (2/2) • Embedded • Affects individual document <html> <head> ... <style type=“text/css”> p {font-family: Arial, sans-serif;} </style></head> <body> ... <p>some text</p> </body> </html>

  6. External Style Sheets (1/4) • Separate text file (.css) • e.g. styles.css p { font-family: Arial, Sans-serif; }

  7. External Style Sheets (2/4) • Linked styles • Affect all documents that are linked to the style sheet <html> <head> ... <link href=“styles.css” rel=“stylesheet” type=“text/css” /> </head> <body> ... <p>some text</p> </body> </html>

  8. External Style Sheets (3/4) • Imported styles (1/2) • Affect all documents that are linked to the style sheet • Not supported by level 4 browsers • Often used to hide CSS2 styles from older browsers

  9. External Style Sheets (4/4) • Imported styles (2/2) Into HTML file <head> ... <style type=“text/css”> <!-- import url(“styles.css”); --> </style> </head> Into another style sheet (sectionstyles.css)- @import instruction must be first line of file! @import url(“styles.css”); /*sectionstyles start here*/ h1 { font-size: 200%; color: #6b84b5 }

  10. Order of precedence • HTML formatting instructions (e.g. <font> tags) • Inline styles • Embedded styles • Linked styles • Imported styles • Default browser styles

  11. Types of CSS styles • Styles assigned to a HTML element • Class selector styles • Define different styles for one or more HTML elements • Assigned to the class attribute within an HTML element • ID selector styles • Define different styles for one and the same HTML element • Assigned to the ID attribute within an HTML element

  12. Class selector styles • CSS: … .blue {color: #082984} .red {color: #de2131} • HTML … <h1 class=“red”>Headline</h1> <p class=“red”>a summary</p> <p class=“blue”>some text</p> …

  13. Pseudo-classes • Used when an HTML element can display more than one behaviour (e.g. hyperlinks) • CSS: a:link {color: #000} a:visited {color: #000} a:hover {color: #69f} a:active {color: #000} • HTML <a href=“nextpage.html”>Next page</a>

  14. ID Selector styles • CSS … #red_heading {color: red} #summary {color: red} p#conclusion {color: blue} • HTML … <h1 id=“red_heading”>Headline</h1> <p id=“summary”>Summary</p> <p id=“conclusion”>Conclusion</p> …

  15. Further resources • Netskills training material http://www.netskills.ac.uk(We’ve got a site license for this material, but you need to register!) • World Wide Web Consortiumhttp://www.w3.org/Style/CSS/

  16. Cascading Style Sheets Part 1 Library and Information Services, University of St Andrews

  17. What next? • Create a Dreamweaver site using the files on floppy disk as a basis for your site - FTP Host: www.st-andrews.ac.uk - Login: [your username] • Check hyperlinks and correct them where necessary • Delete all HTML formatting information in file aboutme.html • Create a style sheet as described in your handout

More Related