Lecture2 CSS1


Published on

Published in: Education, Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • Show CSS Zen Garden - Dave Shea (pronouned "shay") Show CSS Zean Garden files - same HTML for all versions.
  • Show web standards project site with Acid2 test. Internet Explorer 5.0 for the Macintosh, shipped in March of 2000, was the first browser to have full (better than 99 per cent) CSS1 support. Microsoft Internet Explorer , whose version 6 lacks support for about 30 percent of CSS2 properties, and, more significantly, misinterprets a significant number of important properties, such as "width", "height", and "float". "We fully recognize that IE is behind the game today in CSS support. We’ve dug through the Acid 2 Test and analyzed IE’s problems with the test in some great detail, and we’ve made sure the bugs and features are on our list - however, there are some fairly large and difficult features to implement, and they will not all sort to the top of the stack in IE7. I believe we are doing a much better service to web developers out there in IE7 by fixing our known bang-your-head-on-the-desk bugs and usability problems first, and prioritizing the most commonly-requested features based on all the feedback we've had." - http://blogs.msdn.com/ie/archive/2005/07/29/445242.aspx
  • You can use multiple linked or imported style sheets.
  • You can use multiple linked or imported style sheets.
  • User "!important" rules override author "!important" rules. This CSS feature improves accessibility of documents by giving users with special requirements (large fonts, color combinations, etc.) control over presentation.
  • Play with inheritance code. - Show that font face inherits automatically. - Show that background color does not automatically inherit but text color does. - Show that list color is automatic, show how to force border inhertitance.
  • Lecture2 CSS1

    1. 1. Lecture 2: CSS I SFDV2001 Web Development
    2. 2. Cascading Style Sheets <ul><li>You have experienced the limitation of presentation control in transitional HTML. </li></ul><ul><li>Now you can forget about deprecated tags and experience the highly advanced presentation control afforded by CSS. </li></ul><ul><li>With CSS: </li></ul><ul><ul><ul><li>One file can completely control the appearance of ALL your HTML files. </li></ul></ul></ul><ul><ul><ul><li>You have much, much greater control over appearance and behaviour of your page content. </li></ul></ul></ul><ul><ul><ul><li>Web sites that use CSS are much easier to alter the appearance of. </li></ul></ul></ul>
    3. 3. Cascading Style Sheets <ul><li>Transitional code is, generally speaking, consistently presented by most browsers. Switching to CSS to control all your presentation means much more work to get satisfactory behavior across a range of browsers. </li></ul><ul><li>The power of CSS means that it is a lot more complicated than transitional HTML. There are many, many new stylistic controls and a new way of thinking about elements on your page. </li></ul><ul><li>Your structural HTML skills need to be sound if you are to use your CSS sensibly. Writing sensible and efficient CSS code is harder than writing good HTML code. </li></ul>
    4. 4. A little background <ul><li>W3C completed the CSS1 specifications in 1996. IE 3, released the same year, had some CSS support. </li></ul><ul><li>CSS2 was published in 1998. </li></ul><ul><li>Not until 2000, when IE 5 for Mac, was released did any browser have &quot;full&quot; CSS1 support. </li></ul><ul><li>No browser has full CSS2 support. </li></ul><ul><li>The latest versions of Safari and Opera pass the Acid2 test. Firefox and IE do not. IE currently fares worst. </li></ul><ul><li>&quot;I’ll go ahead and relieve the suspense by saying we will not pass this test when IE7 ships.&quot; - Chris Wilson (IEBlog) </li></ul>
    5. 5. Getting started <ul><li>Step 1. doctype: </li></ul><ul><li><!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot;> </li></ul><ul><li>When you use CSS your HTML should conform to the HTML 4.01 strict standard. </li></ul><ul><li>Step 2. Get rid of all deprecated tags and attributes: </li></ul><ul><ul><li>font </li></ul></ul><ul><ul><li>align </li></ul></ul><ul><ul><li>bgcolor </li></ul></ul><ul><ul><li>etc. </li></ul></ul><ul><li>Your HTML should only describe the structure of your content, it should ideally contain no formatting information. </li></ul>
    6. 6. Getting started <ul><li>Step 3. Add style information </li></ul><ul><ul><ul><li>Internally: inline and embedded </li></ul></ul></ul><ul><ul><ul><li>Externally: linked and imported </li></ul></ul></ul><ul><li>99% of the time linked is the best option. </li></ul><ul><li>You may opt to have a few single-page specific styles embedded in an HTML document. </li></ul><ul><li>Inline styles are really no better than <font> tags and there are very, very few good reasons for using them. </li></ul><ul><li>Imported and embedded styles can be hidden from older browsers. </li></ul>
    7. 9. CSS Rules <ul><li>Cascading style sheets consist of a series of rules that determine how your HTML content will be displayed. </li></ul><ul><li>Rules take the format: </li></ul><ul><li>selector{ </li></ul><ul><li>property: value; </li></ul><ul><li>} </li></ul><ul><li>For example: </li></ul><ul><li>body{ </li></ul><ul><li>background-color: #ffe89d; </li></ul><ul><li>} </li></ul>
    8. 10. CSS Rules <ul><li>You add further property value pairs to an element's rule to more specifically control its appearance: </li></ul><ul><li>body{ </li></ul><ul><li>background-color: #ffe89d; </li></ul><ul><li>color: #000e78; </li></ul><ul><li>font-family: Arial, sans-serif; </li></ul><ul><li>margin: 5%; </li></ul><ul><li>} </li></ul><ul><li>A style sheet consists of a series of such rules. </li></ul>
    9. 11. Cascading <ul><li>It's probably fairly obvious how the &quot;style sheet&quot; bit of CSS applies, but the &quot;cascading&quot; bit isn't so obvious. </li></ul><ul><li>The cascade in CSS is how styles take precedence over other styles. </li></ul><ul><li>Because you can have many style rules in play, to avoid conflict certain style information overrides other. </li></ul>
    10. 12. The cascade <ul><li>Least powerful: Browser default settings </li></ul><ul><li>User browser settings </li></ul><ul><li>Linked styles * </li></ul><ul><li>Imported styles* </li></ul><ul><li>Embedded styles** </li></ul><ul><li>Inline styles </li></ul><ul><li>Author !important rules </li></ul><ul><li>Most powerful: User !important rules </li></ul>* Later files take precedence over earlier ones. ** Later rules have greater weight.
    11. 13. The cascade <ul><li>You can alter the power hierarchy by using the !important indicator: </li></ul><ul><li>selector{ </li></ul><ul><li>property: value !important; </li></ul><ul><li>} </li></ul><ul><li>!important beats even inline styles. </li></ul><ul><li>Think carefully before wielding such power - you have to ensure that the style is sensible in all circumstances. </li></ul>
    12. 15. Ultimately the user wins <ul><li>Users can take away your power with one click. </li></ul>
    13. 16. Inheritance <ul><li>One of the things that makes CSS so efficient to use is the ability to have style rules inherited between parent and child elements. </li></ul><ul><li>Parent Child </li></ul><ul><li><html> <body> </li></ul><ul><li><ol> <li> </li></ul><ul><li><ul> <li> </li></ul><ul><li><table> <tr> </li></ul><ul><li><tr> <td> </li></ul>
    14. 17. Inheritance
    15. 18. Inheritance Alter to suit
    16. 19. Inheritance <ul><li>Many CSS properties are automatically inherited from an element's parent. </li></ul><ul><li>You can explicitly set a property's value to inherit. </li></ul><ul><li>Everything contained within you <body> tags is a child of the body. </li></ul><ul><li>So, properties set for the body can be inherited by its children (like <p> or <h1> etc). </li></ul>
    17. 20. Recommended sites: CSS Zen garden: http://www.csszengarden.com/ A List Apart's CSS articles: http://www.alistapart.com/topics/code/css/ W3C's CSS Home Page: http://www.w3.org/Style/CSS/ Further reading: Cascading Style Sheets the Definitive Guide by Eric A. Meyer CSS Cookbook by Christopher Schmitt
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.