SlideShare a Scribd company logo
INTRODUTION TO CSS
2
Background
 Presentation vs. Structure
 An early goal of the WWW
 Easy to update many pages at once
 Easier to maintain consistency
 Early goal: authors' vs. readers' rules
Now partly respected by major browsers
 CSS 1  CSS 2
Extended the scope of the rules
3
 Ignoring most of the incompatibilities for now
 To get an overall understanding
 Later slides will show some details
 We'll examine 4 interesting parts of the
presentational instructions and options later
 But first we'll see
 What it can do (CSS Zen Garden,CSS Examples)
 & How it works
CS Student Overview of CSS
Colour Font Border Positio
n
4
What's Next?
 Introduction to CSS rule method
 CSS selectors
 How CSS matches rules to elements
 The parse tree
 The cascade
 How to include rules in an XHTML file
 A simple example
 Visual formatting and Dual presentation
5
How CSS Works — Rules
 Rules provide presentation hints to browser
 Browser can ignore hints
 Three sources of rules:
 User agent (browser's default settings),
 Webpage (source file),
 The user (personal settings in the browser)
 Rules apply when selectors match context
 E.g. p {text-indent:1.5em }
 Selector is p (matches any <p> element)
6
Rules
 Attached to elements
 As attributes of elements (inline style)
 Tied to id attribute of elements
 Tied to class attribute of elements
 Rules all have form
 {Property Name : Value;}
 Multiple rules separated by ;
7
Selectors
 Can apply to every element of a type
E.g. h2
 More often to a class of element
 <cite class="textbook book">
 Matches both textbook and book
 Can apply to pseudo-elements
a:visited, etc.
8
Special Elements
div and span
 Only for grouping other elements
 div is block-level (think about paragraphs)
 span is in-line (think about <code>)
9
Selectors (cont.)
 E
 E1 E2
 E1 > E2
 E1 + E2
 E#id
id
 E.class
class
 See the handout for more pattern matches
 Resources about selectors are listed on a later slide (just after
the cascade)
The selector always
refers to the
rightmost element
10
How CSS Works — Matching
 Every XHTML document represents a document
tree
 The browser uses the tree to determine which rules
apply
 What about inheritance? And conflicts?
12
HTML Parse Tree
<html>
<head>
<meta … />
<title>…</title>
</head>
<body>
<h1>…</h1>
<p>…<span>…</span>…</p>
<ul>
<li>…</li>
<li>…</li>
<li>…<span>…</span>…</li>
</ul>
<p>…</p>
</body>
</html>
What will h1 + p match?
What will ul > span match?
What will ul {color:blue}
do?
13
Inheritance in CSS
 The Cascade
 Inheritance moves down tree
 Cascading move horizontally
 It works on elements that the same rules apply to
 It is only used for tie-breaking when ≥2 rules apply
 The highest ranking rule wins
 Most specific wins (usually)
 But important rules override others
 !important beats plain
 User's !important beats everything else
14
Details of the CSS 2.1 Cascade
For each element E
1. Find all declarations that apply to E
2. Rank those declarations by origin
a. user !important > author !important > inline style
b. inline style > author plain > user plain > browser
3. If there is not a clear winner then most specific rule
wins.
 Compute specificity as shown on next 2 slides.
15
CSS 2.1 Cascade (Continued)
3. Compute specificity thus:
a. If one rule uses more # symbols than the others then it
applies, otherwise …
b. If one rule uses more attributes (including class
class) than
the others then it applies, otherwise …
c. If one rule uses more elements then it applies
d. For each two rules that have the same number of every
one of the above specifiers, the one that was declared
last applies
 class is the only attribute that can be selected
with the .
. in CSS
 An equivalent method is shown on the next slide
16
CSS 2.1 Cascade Computation
 The cascade algorithm in the standard uses a semi-
numerical algorithm
 The computation looks like this:
 The specificity is a×base3
+ b×base2
+ c×base + d
 Where base = 1 + maximum(b,c,d)
 The rule with the largest specificity applies
1 if the selector is an inline style
a =
0 otherwise
b = Number of id attributes (but only if specified with #)
c = Number of attributes (except those in b) and pseudo-attributes specified
d = Number of non-id elements specified (including pseudo-elements)
class is an attribute
 Elements
 :first-line
 :first-letter
 :before,
 :after
Pseudo-Elements?
Pseudo-Attributes?!
 Classes
 :first-child
 :link,
 :visited
 :hover,
 :active,
 :focus
 :lang
CSS 2.1 §5.10
Pseudo-elements
and pseudo-classes
‘CSS introduces the concepts of pseudo-elements and pseudo-classes to
permit formatting based on information that lies outside the document tree.’
18
How To Include Rules
 Inline
 <p style=“text-align: center” >…</p>
 Inside the head element
 <link rel="stylesheet"
type="text/css" href="site.css" />
 <style type="text/css">…</style>
 <style type="text/css">
 @import url(site.css);
 /* other rules could go here */
</style>
19
Simple Example
 Fonts and background colours
 Inheritance and cascading
 See simple in CSS examples
20
A Very Brief Overview of
Visual Formatting With CSS
 Visual Formatting
 Fonts
 Colours
 Position
 Box model and Borders
 Dual presentation / Hiding CSS
21
Visual Formatting: fonts
 Some major properties
 font-family
 body {font-family: Garamond, Times, serif}
 Serif fonts and sans-serif fonts
 font-size:
Length (em,ex), percentage, relative size, absolute size
 font-style:
Normal, italic, oblique
 font-weight:
Lighter, normal, bold, bolder, 100, 200, …, 800, 900
 Set all at once with font
22
Visual Formatting: Colours
 How to specify
 16 Predefined names
 RGB values (%, #, 0…255)
 System names: e.g. CaptionText
 Dithered Colour
 See Lynda Weinman's charts
 Okay for photos, etc.
23
Visual Formatting: Colours (cont.)
 Major properties
 background-color
 color
 transparent and inherit values
24
Visual Formatting: Images
 position:
static, relative, absolute, fixed
 Static — normal elements
 Relative — translate from usual position
 Absolute — scroll with the page
 Fixed — like absolute, but don't scroll away
 Example: Jon Gunderson
25
Visual Formatting: Images (cont.)
 z-index: depth
 float and clear
 float: left or float: right or float: none
Position relative to parent element
 Reset with clear
<br style="clear:both" />
26
Visual Formatting: Box Model
Margin
Border
Padding
Figure from materials © by Dietel, Dietel, and Nieto
27
Borders? Do we have borders!
 Four types again
 Can all be set at once with border
 See Border slides by Jon Gunderson
28
Box Model (Cont.)
 Padding
 Size in %, em, or ex for text
 padding-top, padding-right, padding-bottom, padding-left
Mnemonic: TRouBLe
 Set all at once with padding
 Margin
 Similar to padding
 But can also be auto
see centring example
Width is of content only.
Neither the border nor the
padding are included in width.
29
Making Room for a
fixed position object
body
{margin-left: 6.3em}
div.up
{position: fixed;
left: 1em;
top: 40%;
padding: .2ex;
min-width: 5.5ex }
Width computation: see <URL:
http://tantek.com/CSS/Examples/boxmodelhack.html>
30
Formatting The ‘Jump Box’
‘Jump Box’
31
Basic Formatting of the
‘Jump Box’
Extract of CSS Rules
body
{margin-left: 6.3em}
div.up
{position: fixed;
left: 1em;
top: 40%;
padding: .2ex;
min-width: 5.5ex }
HTML Outline
<body>
<!-- … -->
<div class="up">
<dl>
<dt>Jump to
top</dt>
<!-- … -->
</div>
</body>
32
Effects of Box Formatting
33
body {padding:4em}
34
div.up {margin: 4em}
35
div.up dl {margin:4em}
36
CSS For Dual Presentation
 What if users don't have CSS?
See button example
 What if CSS only sortof works?
Tricks to hide CSS from dumb browsers
 How can I make cool webpages?
One of many ways: see W3C Core Styles
37
Hiding CSS —
Why do we need to?
 Two failure modes: graceful and catastrophic
 Pragmatism
 Hubris
38
A Trick For Dual Presentation
visibility:
visible or hidden
display:
none
visibility example (CSS buttons)
visible:hidden
element can't be seen
but it still uses space
display:none
element isn't shown
39
Hiding CSS — How (overview)
 Ensure that markup is meaningful without CSS
 Order of presentation
 Extra/hidden content
 Make styles in layers
 v4.0 browsers don’t recognize @import
 Some browsers ignore media rules
 Later, and more specific, rules override other rules
 Use parsing bugs for browser detection
 Example follows
 Use browser-specific Javascript
 Server-side detection doesn’t work well
 Too much spoofing
40
Hiding CSS — Some details
 IE 5 for Windows computes incorrect sizes
 It also doesn’t understand voice-family, so…
p {
font-size: x-small; /* for Win IE 4/5 only */
voice-family: ""}"";
/* IE thinks rule is over */
voice-family: inherit; /* recover from trick */
font-size: small /* for better browsers */
}
html>p {font-size: small} /* for Opera */
Credits follow
41
Hiding CSS — Caveats
 There are no fool-proof workarounds for every bug
in every browser
 Some workarounds are incompatible with strict
XHTML
 The workarounds take time and are sometimes
inelegant
 But they are necessary if you want to reach the
largest possible audience
 For more about hacks see
<URL:http://tantek.com/log/2005/11.html>
42
Hiding CSS — Credits
The example was adapted from
 p. 324 of Designing with web standards by Jeffrey
Zeldman (©2003 by the author, published by New
Riders with ISBN 0-7357-1201-8)
The methods are due to
 Tantek Çelick (who also created much of Mac IE
and much else)
Basic Knowldege about CSS Prepared for VV softech solution (2).ppt
Basic Knowldege about CSS Prepared for VV softech solution (2).ppt

More Related Content

Similar to Basic Knowldege about CSS Prepared for VV softech solution (2).ppt (20)

PDF
Professional Css
Subramanyan Murali
 
PPTX
CSS.pptx
VijayKumarLokanadam
 
PPTX
Module 2 CSS . cascading style sheet and its uses
BKReddy3
 
PDF
Chapter 3 - CSS.pdf
wubiederebe1
 
PDF
The CSS Handbook
jackchenvlo
 
PPT
Css class-02
Md Ali Hossain
 
PPTX
CSS
Akila Iroshan
 
PDF
Webpage style with CSS
Hemant Patidar
 
PDF
Styling Your Web Pages with Cascading Style Sheets / EDU course / University ...
Patrick Lauke
 
PPT
IP - Lecture 6, 7 Chapter-3 (3).ppt
kassahungebrie
 
PDF
ch-hguygureehuvnvdfduyertiuhrnhduuyfjh3.pdf
kasutaye192
 
PPT
CSS Training in Bangalore
rajkamal560066
 
PPT
Make Css easy(part:2) : easy tips for css(part:2)
shabab shihan
 
PPT
CSS Overview
Doncho Minkov
 
PPT
Css week11 2019 2020 for g10 by eng.osama ghandour
Osama Ghandour Geris
 
PPTX
Cascading Style Sheets
Senthil Kumar
 
PPTX
CSS Walktrough Internship Course
Zoltan Iszlai
 
PDF
Introduction to cascade style sheets CSS.pdf
Mahmoud268161
 
Professional Css
Subramanyan Murali
 
Module 2 CSS . cascading style sheet and its uses
BKReddy3
 
Chapter 3 - CSS.pdf
wubiederebe1
 
The CSS Handbook
jackchenvlo
 
Css class-02
Md Ali Hossain
 
Webpage style with CSS
Hemant Patidar
 
Styling Your Web Pages with Cascading Style Sheets / EDU course / University ...
Patrick Lauke
 
IP - Lecture 6, 7 Chapter-3 (3).ppt
kassahungebrie
 
ch-hguygureehuvnvdfduyertiuhrnhduuyfjh3.pdf
kasutaye192
 
CSS Training in Bangalore
rajkamal560066
 
Make Css easy(part:2) : easy tips for css(part:2)
shabab shihan
 
CSS Overview
Doncho Minkov
 
Css week11 2019 2020 for g10 by eng.osama ghandour
Osama Ghandour Geris
 
Cascading Style Sheets
Senthil Kumar
 
CSS Walktrough Internship Course
Zoltan Iszlai
 
Introduction to cascade style sheets CSS.pdf
Mahmoud268161
 

More from testvarun21 (6)

PPTX
SQLBasic to advance for the beggineers.pptx
testvarun21
 
PPTX
JS-Basic for beginners and advances.pptx
testvarun21
 
PPT
INTRO TO JAVASCRIPT basic to adcance.ppt
testvarun21
 
PPTX
Salesforce Certification complete details .pptx
testvarun21
 
PPT
Javascript for beggineers Lecture 4 (1).ppt
testvarun21
 
PPT
Internship HTML_Day-1 for beggineers.ppt
testvarun21
 
SQLBasic to advance for the beggineers.pptx
testvarun21
 
JS-Basic for beginners and advances.pptx
testvarun21
 
INTRO TO JAVASCRIPT basic to adcance.ppt
testvarun21
 
Salesforce Certification complete details .pptx
testvarun21
 
Javascript for beggineers Lecture 4 (1).ppt
testvarun21
 
Internship HTML_Day-1 for beggineers.ppt
testvarun21
 
Ad

Recently uploaded (20)

PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
July Patch Tuesday
Ivanti
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
July Patch Tuesday
Ivanti
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Ad

Basic Knowldege about CSS Prepared for VV softech solution (2).ppt

  • 2. 2 Background  Presentation vs. Structure  An early goal of the WWW  Easy to update many pages at once  Easier to maintain consistency  Early goal: authors' vs. readers' rules Now partly respected by major browsers  CSS 1  CSS 2 Extended the scope of the rules
  • 3. 3  Ignoring most of the incompatibilities for now  To get an overall understanding  Later slides will show some details  We'll examine 4 interesting parts of the presentational instructions and options later  But first we'll see  What it can do (CSS Zen Garden,CSS Examples)  & How it works CS Student Overview of CSS Colour Font Border Positio n
  • 4. 4 What's Next?  Introduction to CSS rule method  CSS selectors  How CSS matches rules to elements  The parse tree  The cascade  How to include rules in an XHTML file  A simple example  Visual formatting and Dual presentation
  • 5. 5 How CSS Works — Rules  Rules provide presentation hints to browser  Browser can ignore hints  Three sources of rules:  User agent (browser's default settings),  Webpage (source file),  The user (personal settings in the browser)  Rules apply when selectors match context  E.g. p {text-indent:1.5em }  Selector is p (matches any <p> element)
  • 6. 6 Rules  Attached to elements  As attributes of elements (inline style)  Tied to id attribute of elements  Tied to class attribute of elements  Rules all have form  {Property Name : Value;}  Multiple rules separated by ;
  • 7. 7 Selectors  Can apply to every element of a type E.g. h2  More often to a class of element  <cite class="textbook book">  Matches both textbook and book  Can apply to pseudo-elements a:visited, etc.
  • 8. 8 Special Elements div and span  Only for grouping other elements  div is block-level (think about paragraphs)  span is in-line (think about <code>)
  • 9. 9 Selectors (cont.)  E  E1 E2  E1 > E2  E1 + E2  E#id id  E.class class  See the handout for more pattern matches  Resources about selectors are listed on a later slide (just after the cascade) The selector always refers to the rightmost element
  • 10. 10 How CSS Works — Matching  Every XHTML document represents a document tree  The browser uses the tree to determine which rules apply  What about inheritance? And conflicts?
  • 11. 12 HTML Parse Tree <html> <head> <meta … /> <title>…</title> </head> <body> <h1>…</h1> <p>…<span>…</span>…</p> <ul> <li>…</li> <li>…</li> <li>…<span>…</span>…</li> </ul> <p>…</p> </body> </html> What will h1 + p match? What will ul > span match? What will ul {color:blue} do?
  • 12. 13 Inheritance in CSS  The Cascade  Inheritance moves down tree  Cascading move horizontally  It works on elements that the same rules apply to  It is only used for tie-breaking when ≥2 rules apply  The highest ranking rule wins  Most specific wins (usually)  But important rules override others  !important beats plain  User's !important beats everything else
  • 13. 14 Details of the CSS 2.1 Cascade For each element E 1. Find all declarations that apply to E 2. Rank those declarations by origin a. user !important > author !important > inline style b. inline style > author plain > user plain > browser 3. If there is not a clear winner then most specific rule wins.  Compute specificity as shown on next 2 slides.
  • 14. 15 CSS 2.1 Cascade (Continued) 3. Compute specificity thus: a. If one rule uses more # symbols than the others then it applies, otherwise … b. If one rule uses more attributes (including class class) than the others then it applies, otherwise … c. If one rule uses more elements then it applies d. For each two rules that have the same number of every one of the above specifiers, the one that was declared last applies  class is the only attribute that can be selected with the . . in CSS  An equivalent method is shown on the next slide
  • 15. 16 CSS 2.1 Cascade Computation  The cascade algorithm in the standard uses a semi- numerical algorithm  The computation looks like this:  The specificity is a×base3 + b×base2 + c×base + d  Where base = 1 + maximum(b,c,d)  The rule with the largest specificity applies 1 if the selector is an inline style a = 0 otherwise b = Number of id attributes (but only if specified with #) c = Number of attributes (except those in b) and pseudo-attributes specified d = Number of non-id elements specified (including pseudo-elements) class is an attribute
  • 16.  Elements  :first-line  :first-letter  :before,  :after Pseudo-Elements? Pseudo-Attributes?!  Classes  :first-child  :link,  :visited  :hover,  :active,  :focus  :lang CSS 2.1 §5.10 Pseudo-elements and pseudo-classes ‘CSS introduces the concepts of pseudo-elements and pseudo-classes to permit formatting based on information that lies outside the document tree.’
  • 17. 18 How To Include Rules  Inline  <p style=“text-align: center” >…</p>  Inside the head element  <link rel="stylesheet" type="text/css" href="site.css" />  <style type="text/css">…</style>  <style type="text/css">  @import url(site.css);  /* other rules could go here */ </style>
  • 18. 19 Simple Example  Fonts and background colours  Inheritance and cascading  See simple in CSS examples
  • 19. 20 A Very Brief Overview of Visual Formatting With CSS  Visual Formatting  Fonts  Colours  Position  Box model and Borders  Dual presentation / Hiding CSS
  • 20. 21 Visual Formatting: fonts  Some major properties  font-family  body {font-family: Garamond, Times, serif}  Serif fonts and sans-serif fonts  font-size: Length (em,ex), percentage, relative size, absolute size  font-style: Normal, italic, oblique  font-weight: Lighter, normal, bold, bolder, 100, 200, …, 800, 900  Set all at once with font
  • 21. 22 Visual Formatting: Colours  How to specify  16 Predefined names  RGB values (%, #, 0…255)  System names: e.g. CaptionText  Dithered Colour  See Lynda Weinman's charts  Okay for photos, etc.
  • 22. 23 Visual Formatting: Colours (cont.)  Major properties  background-color  color  transparent and inherit values
  • 23. 24 Visual Formatting: Images  position: static, relative, absolute, fixed  Static — normal elements  Relative — translate from usual position  Absolute — scroll with the page  Fixed — like absolute, but don't scroll away  Example: Jon Gunderson
  • 24. 25 Visual Formatting: Images (cont.)  z-index: depth  float and clear  float: left or float: right or float: none Position relative to parent element  Reset with clear <br style="clear:both" />
  • 25. 26 Visual Formatting: Box Model Margin Border Padding Figure from materials © by Dietel, Dietel, and Nieto
  • 26. 27 Borders? Do we have borders!  Four types again  Can all be set at once with border  See Border slides by Jon Gunderson
  • 27. 28 Box Model (Cont.)  Padding  Size in %, em, or ex for text  padding-top, padding-right, padding-bottom, padding-left Mnemonic: TRouBLe  Set all at once with padding  Margin  Similar to padding  But can also be auto see centring example Width is of content only. Neither the border nor the padding are included in width.
  • 28. 29 Making Room for a fixed position object body {margin-left: 6.3em} div.up {position: fixed; left: 1em; top: 40%; padding: .2ex; min-width: 5.5ex } Width computation: see <URL: http://tantek.com/CSS/Examples/boxmodelhack.html>
  • 29. 30 Formatting The ‘Jump Box’ ‘Jump Box’
  • 30. 31 Basic Formatting of the ‘Jump Box’ Extract of CSS Rules body {margin-left: 6.3em} div.up {position: fixed; left: 1em; top: 40%; padding: .2ex; min-width: 5.5ex } HTML Outline <body> <!-- … --> <div class="up"> <dl> <dt>Jump to top</dt> <!-- … --> </div> </body>
  • 31. 32 Effects of Box Formatting
  • 35. 36 CSS For Dual Presentation  What if users don't have CSS? See button example  What if CSS only sortof works? Tricks to hide CSS from dumb browsers  How can I make cool webpages? One of many ways: see W3C Core Styles
  • 36. 37 Hiding CSS — Why do we need to?  Two failure modes: graceful and catastrophic  Pragmatism  Hubris
  • 37. 38 A Trick For Dual Presentation visibility: visible or hidden display: none visibility example (CSS buttons) visible:hidden element can't be seen but it still uses space display:none element isn't shown
  • 38. 39 Hiding CSS — How (overview)  Ensure that markup is meaningful without CSS  Order of presentation  Extra/hidden content  Make styles in layers  v4.0 browsers don’t recognize @import  Some browsers ignore media rules  Later, and more specific, rules override other rules  Use parsing bugs for browser detection  Example follows  Use browser-specific Javascript  Server-side detection doesn’t work well  Too much spoofing
  • 39. 40 Hiding CSS — Some details  IE 5 for Windows computes incorrect sizes  It also doesn’t understand voice-family, so… p { font-size: x-small; /* for Win IE 4/5 only */ voice-family: ""}""; /* IE thinks rule is over */ voice-family: inherit; /* recover from trick */ font-size: small /* for better browsers */ } html>p {font-size: small} /* for Opera */ Credits follow
  • 40. 41 Hiding CSS — Caveats  There are no fool-proof workarounds for every bug in every browser  Some workarounds are incompatible with strict XHTML  The workarounds take time and are sometimes inelegant  But they are necessary if you want to reach the largest possible audience  For more about hacks see <URL:http://tantek.com/log/2005/11.html>
  • 41. 42 Hiding CSS — Credits The example was adapted from  p. 324 of Designing with web standards by Jeffrey Zeldman (©2003 by the author, published by New Riders with ISBN 0-7357-1201-8) The methods are due to  Tantek Çelick (who also created much of Mac IE and much else)

Editor's Notes

  • #26: From slides to accompany Internet & World Wide Web: How to Program by Dietel, et al. published by Prentice-Hall in 2000.