SlideShare a Scribd company logo
1 of 54
CSS Essentials
For the one who care about layout




                 Tin@BrowBag 3 June 2011
Agenda
XHTML & CSS
CSS selector
Visual formatting & models
Basic sample
Advanced sample
Tricks and hacks
CSS define the visual model
Layout
Typography
Units
Rendering
Graphics
etc.
Era of CSS
Before the   movable-   Moden publishing
dawn         type
                        CSS 3
Agenda
XHTML & CSS
CSS selector
Visual formatting & models
Basic sample
Advanced sample
Tricks and hacks
XHTML and CSS
XHTML => data (structure)
CSS => presentation (visual)
Separation of concerns
Best practices:
  Use proper HTML tags
  Use meaningful class/id name (red-text warn-text)
  Minimizing HTML structure and CSS rules
Example of html
Agenda
XHTML & CSS
CSS selector
Visual formatting & models
Basic sample
Advanced sample
Tricks and hacks
CSS selector - Rule Structure
Selector             Declaration block

            Declaration        Declaration

  H1       { color: red;    background: yellow;   }


           Property Value    Property    Value
CSS selector - Basic
Element Selector
  Type selector: h1 { font-weight: bold;}
  Descendant selector: li a { text-decoration: none; }
Class Selector
  .warn { color: red }
  .full-width { width: 100% }
CSS selector - Basic
ID Selector
  #sidebar { float: right; width: 27em; }
Pseudo class
  a:link { color: blue; }
  li:hover { background-color: grey; }
  input:focus { background-color: yellow; }
  All pseudo class:
    :active, :after, :before, :first-child, :first-letter, :first-
    line, :focus, :hover, :lang, :link, :visited
CSS selector - advanced
Universal (wildcard) Selector
  * { padding: 0; margin: 0; }
Child selector: #nav > li
Adjacent Sibling selector: h1 + p
Simple Attribute selector:
  div[class]
  input[type=”input”], div[id~=”container”] ...
CSS Rule Specificity (Weight)
 Four level of specificity
   level 1(1000): inline style, <div style=”color: red”>
   level 2(0100): ID selector
   level 3(0010): class, pseudo class, attribute selector
   level 4(0001): element selector, universal selector
   Special level: !important (except IE6)
   Draw game: last declaration win
CSS Rule Specificity
Rule                    Weight      Weight (digit)
Style=””               1, 0, 0, 0      1000
#wrapped #content {}   0, 2, 0, 0       200
#content .date {}      0, 1, 1, 0       110
div#content {}         0, 1, 0, 1       101
#content {}            0, 1, 0, 0       100
p.comment .date {}     0, 0, 2, 1        21
p.comment {}           0,0, 1, 1         11
div p {}               0, 0, 0, 2         2
p {}                   0, 0, 0, 1         1
CSS: Inherit and cascading

Inheritance: Inherit ancestor element’s style, color,
font-size (font*)
  descendants in dom tree inherit ancestor’s style
  none inherit: padding, margin, border, background
  no specificity (lowest priority)
CSS: Inherit and cascading
Cascading: different level of css rule composite
together
  all match selector declarations will be applied
    browser default style
    Inheritance
    selector declarations from lower to higher specificity
    the styles with !important
    later property overwrite former property
How to use them?
Real example (by Firebug)
Agenda
XHTML & CSS
CSS selector
Visual formatting & models
Basic sample
Advanced sample
Tricks and hacks
Element Classification
Nonreplaced Elements
  The majority of HTML elements are NE
  Their content box is generate by itself
Replaced Elements
  content box is replaced by something not directly
  represented by document content
  Image, flash object, input element
Everything start form the ‘display’ model



“The display property
specifies the type of box
an element should
generate.”
Era of CSS
Before the   movable-   Moden publishing
dawn         type
                        CSS 3
What’s the box?
Basic Box model
     margin: top right bottom left;
                border
               padding
        width

            Content Area
                        height
Basic Box model                  Background
     margin: top right bottom left;
                border
               padding
        width

            Content Area
                        height
Box model example (in firebug)
IE box model quirks
                                                                             W3C
                                                                                    Actual width = margin * 2 + padding*2 +
                                                                                    border * 2 + width (css property)

                                                                                    content-width = width (css property)

                                                                             IE
                                                                                    Actual width = margin * 2 + width (css
                                                                                    property)

                                                                                    content-width = width - padding * 2


This file is licensed under the Creative Commons Attribution ShareAlike 3.0 Unported (http://en.wikipedia.org/wiki/Image:W3C_and_Internet_Explorer_box_models.png)
So... for IE compatibility

 Normally, don’t use padding and margin on same
 element, use it in different level
 Make IE doesn't work in quirks-mode
 Has-layout=true (zoom: 1, but can’t pass w3c validation)
 Don’t use width: 100% and padding on same element (for
 safty, use 95% or other safe value)
Element Display Roles - Block Level
 Block-Level is a element with property display: block
 It generate a box fills its parent’s content area
 can’t have other element on it’s side
 it generate breaks before/after it’s box
 Use width/height to determine the size
 min-width/max-width
 Div is block element by default
 Use overflow control overflow content display/hide
Block-Level Layout

It generate a rectangular box called element box, which
describes the amount of space occupied by an element
  Background extends to the outer edge of the border
  Only margins, height, and width may be set to auto
  Only margins can be given negative values
  Padding & borders of element box default to 0 & none
  Width property define only the width of content area
Block box formating

        margin: top right bottom left;
                   border
                  padding
           width

               Content Area
                           height
Block box formating
        The containing block
                                                                      border
                                                                      padding
                  auto margin                             width
                                                                  Content Area
                                                                                 height




negative margin
                                                                     border
                                                                      padding
                                         width
                                                                  Content Area
                                                                                          height




                                   border
                                   padding
   fixed margin          width
                                Content Area
                                                 height
                                                                                          Fixed width
Element Display Roles - Inline Level
 Inline-level is a element with property display: inline
 It generate element box within a line of text and do not
 break up the flow of that line, continues layout
 The box size is determined by it’s content
 inline element can only contain inline element
 Margin has no effect here
 line-height and vertical-align
 inline-height, inline-width (not recommended)
 font-size
Inline-Level Layout

content
 area           inline element              inline box


              content area   half-leading


  which is   Strongly emphasized      and which is
Inline-Level Layout

content
 area           inline element              inline box


              content area   half-leading


  which is   Strongly emphasized       and which is


                                 baseline
Inline box formating

  The containing block
    which is   Strongly emphasized   which is

    beijing oepn party   is good
Normal layout flow
Other Element Display Roles

Inline-block: it has no breaks, but you can specific
width and height on it
display: none (totally hide the content, remove it from
layout flow)
  about visibility: hide (do not display the content, but
  still take effect in layout flow)
Steal from http://www.slideshare.net/stopsatgreen/the-home-of-tomorrow-css-layouts

Future Layout Modules
Steal from http://www.slideshare.net/stopsatgreen/the-home-of-tomorrow-css-layouts

Future Layout Modules
Steal from http://www.slideshare.net/stopsatgreen/the-home-of-tomorrow-css-layouts

Future Layout Modules
Steal from http://www.slideshare.net/stopsatgreen/the-home-of-tomorrow-css-layouts

Future Layout Modules
Steal from http://www.slideshare.net/stopsatgreen/the-home-of-tomorrow-css-layouts

Future Layout Modules
Control the layout
 Floating Layout            Absolute positioning
   Left, right float         Fixed positioning
   Clear float               z-index
   Shrink to fit           Table Layout
 Positioning Layout         Fixed table layout
   Static positioning       Automatic table layout
   Relative positioning
Values and Units
Color Values                  Length Values
  #RRGGBB                       Absolute length units
  #RGB                            Inches (in)
  rgb(rrr.rr%, ggg.gg%,           Centimeters (cm)
  bbb.bb%)
                                  Millimeters (mm)
  rgb(rrr, ggg, bbb)
                                  Points (pt) 12pt = 1in
  keyword (black, blue ...)
                                  Picas (pc)
Values and Units
Length Values
  Relative length units
    em-height (em)
    x-height (ex)
    Pixels (px)
Percentage Values (%)
Agenda
XHTML & CSS
CSS selector
Visual formatting & models
Basic sample
Advanced sample
Tricks and hacks
CSS basic example
Style for font (size, weight, color, style, family)
Style for link
  love/hate
  rollover (spry)
Style for float image and clear
Style for background
Agenda
XHTML & CSS
CSS selector
Visual formatting & models
Basic sample
Advanced sample
Tricks and hacks
CSS Advanced example
Image button      rounded corner
horizontal menu     fixed width
css tooltip         mountain corner
slide door tab      4 wrapped bg images
                    4 corner images
                    css rounded corner
Agenda
XHTML & CSS
CSS selector
Visual formatting & models
Basic sample
Advanced sample
Tricks and hacks
Hacks and Tricks
Most hacks is for IE          Tricks for IE
  Star hack (6)                 min-width/width(6)
  Underscore hack (7)           <!--[if lte IE 7]>
  !important (6)                 <![endif]-->
  > child selector (-5, -6)
  property selector
  has-layout? zoom: 1
You are coming a long way,
baby
Thanks!

More Related Content

Similar to Css Essential (20)

Web Layout
Web LayoutWeb Layout
Web Layout
 
Lecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
Lecture 10 CSS part 2.pptxvvvvvvvvvvvvvvLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
Lecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
 
5. Web Technology CSS Advanced
5. Web Technology CSS Advanced 5. Web Technology CSS Advanced
5. Web Technology CSS Advanced
 
Dimensions of elements.pdf
Dimensions of elements.pdfDimensions of elements.pdf
Dimensions of elements.pdf
 
Static layouts with css
Static layouts with cssStatic layouts with css
Static layouts with css
 
CSS
CSSCSS
CSS
 
CSS.pptx
CSS.pptxCSS.pptx
CSS.pptx
 
CSS and CSS3
CSS and CSS3CSS and CSS3
CSS and CSS3
 
Box Model
Box ModelBox Model
Box Model
 
Css box model
Css box modelCss box model
Css box model
 
CSS Foundations, pt 2
CSS Foundations, pt 2CSS Foundations, pt 2
CSS Foundations, pt 2
 
Web Development - Lecture 6
Web Development - Lecture 6Web Development - Lecture 6
Web Development - Lecture 6
 
Html5
Html5Html5
Html5
 
Responsive web design
Responsive web designResponsive web design
Responsive web design
 
Lecture-8.pptx
Lecture-8.pptxLecture-8.pptx
Lecture-8.pptx
 
Concept of CSS part 2
Concept of CSS part 2Concept of CSS part 2
Concept of CSS part 2
 
Accessibility and css - Lisa Seeman
Accessibility and css - Lisa SeemanAccessibility and css - Lisa Seeman
Accessibility and css - Lisa Seeman
 
Css training
Css trainingCss training
Css training
 
Cascading Style Sheets - Part 01
Cascading Style Sheets - Part 01Cascading Style Sheets - Part 01
Cascading Style Sheets - Part 01
 
Working-With-The-Box-Model-Lesson-5.pptx
Working-With-The-Box-Model-Lesson-5.pptxWorking-With-The-Box-Model-Lesson-5.pptx
Working-With-The-Box-Model-Lesson-5.pptx
 

Recently uploaded

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 

Recently uploaded (20)

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 

Css Essential

  • 1. CSS Essentials For the one who care about layout Tin@BrowBag 3 June 2011
  • 2. Agenda XHTML & CSS CSS selector Visual formatting & models Basic sample Advanced sample Tricks and hacks
  • 3. CSS define the visual model Layout Typography Units Rendering Graphics etc.
  • 4. Era of CSS Before the movable- Moden publishing dawn type CSS 3
  • 5. Agenda XHTML & CSS CSS selector Visual formatting & models Basic sample Advanced sample Tricks and hacks
  • 6. XHTML and CSS XHTML => data (structure) CSS => presentation (visual) Separation of concerns Best practices: Use proper HTML tags Use meaningful class/id name (red-text warn-text) Minimizing HTML structure and CSS rules
  • 8. Agenda XHTML & CSS CSS selector Visual formatting & models Basic sample Advanced sample Tricks and hacks
  • 9. CSS selector - Rule Structure Selector Declaration block Declaration Declaration H1 { color: red; background: yellow; } Property Value Property Value
  • 10. CSS selector - Basic Element Selector Type selector: h1 { font-weight: bold;} Descendant selector: li a { text-decoration: none; } Class Selector .warn { color: red } .full-width { width: 100% }
  • 11. CSS selector - Basic ID Selector #sidebar { float: right; width: 27em; } Pseudo class a:link { color: blue; } li:hover { background-color: grey; } input:focus { background-color: yellow; } All pseudo class: :active, :after, :before, :first-child, :first-letter, :first- line, :focus, :hover, :lang, :link, :visited
  • 12. CSS selector - advanced Universal (wildcard) Selector * { padding: 0; margin: 0; } Child selector: #nav > li Adjacent Sibling selector: h1 + p Simple Attribute selector: div[class] input[type=”input”], div[id~=”container”] ...
  • 13. CSS Rule Specificity (Weight) Four level of specificity level 1(1000): inline style, <div style=”color: red”> level 2(0100): ID selector level 3(0010): class, pseudo class, attribute selector level 4(0001): element selector, universal selector Special level: !important (except IE6) Draw game: last declaration win
  • 14. CSS Rule Specificity Rule Weight Weight (digit) Style=”” 1, 0, 0, 0 1000 #wrapped #content {} 0, 2, 0, 0 200 #content .date {} 0, 1, 1, 0 110 div#content {} 0, 1, 0, 1 101 #content {} 0, 1, 0, 0 100 p.comment .date {} 0, 0, 2, 1 21 p.comment {} 0,0, 1, 1 11 div p {} 0, 0, 0, 2 2 p {} 0, 0, 0, 1 1
  • 15. CSS: Inherit and cascading Inheritance: Inherit ancestor element’s style, color, font-size (font*) descendants in dom tree inherit ancestor’s style none inherit: padding, margin, border, background no specificity (lowest priority)
  • 16. CSS: Inherit and cascading Cascading: different level of css rule composite together all match selector declarations will be applied browser default style Inheritance selector declarations from lower to higher specificity the styles with !important later property overwrite former property
  • 17. How to use them?
  • 18. Real example (by Firebug)
  • 19. Agenda XHTML & CSS CSS selector Visual formatting & models Basic sample Advanced sample Tricks and hacks
  • 20. Element Classification Nonreplaced Elements The majority of HTML elements are NE Their content box is generate by itself Replaced Elements content box is replaced by something not directly represented by document content Image, flash object, input element
  • 21. Everything start form the ‘display’ model “The display property specifies the type of box an element should generate.”
  • 22. Era of CSS Before the movable- Moden publishing dawn type CSS 3
  • 24. Basic Box model margin: top right bottom left; border padding width Content Area height
  • 25. Basic Box model Background margin: top right bottom left; border padding width Content Area height
  • 26. Box model example (in firebug)
  • 27. IE box model quirks W3C Actual width = margin * 2 + padding*2 + border * 2 + width (css property) content-width = width (css property) IE Actual width = margin * 2 + width (css property) content-width = width - padding * 2 This file is licensed under the Creative Commons Attribution ShareAlike 3.0 Unported (http://en.wikipedia.org/wiki/Image:W3C_and_Internet_Explorer_box_models.png)
  • 28. So... for IE compatibility Normally, don’t use padding and margin on same element, use it in different level Make IE doesn't work in quirks-mode Has-layout=true (zoom: 1, but can’t pass w3c validation) Don’t use width: 100% and padding on same element (for safty, use 95% or other safe value)
  • 29. Element Display Roles - Block Level Block-Level is a element with property display: block It generate a box fills its parent’s content area can’t have other element on it’s side it generate breaks before/after it’s box Use width/height to determine the size min-width/max-width Div is block element by default Use overflow control overflow content display/hide
  • 30. Block-Level Layout It generate a rectangular box called element box, which describes the amount of space occupied by an element Background extends to the outer edge of the border Only margins, height, and width may be set to auto Only margins can be given negative values Padding & borders of element box default to 0 & none Width property define only the width of content area
  • 31. Block box formating margin: top right bottom left; border padding width Content Area height
  • 32. Block box formating The containing block border padding auto margin width Content Area height negative margin border padding width Content Area height border padding fixed margin width Content Area height Fixed width
  • 33. Element Display Roles - Inline Level Inline-level is a element with property display: inline It generate element box within a line of text and do not break up the flow of that line, continues layout The box size is determined by it’s content inline element can only contain inline element Margin has no effect here line-height and vertical-align inline-height, inline-width (not recommended) font-size
  • 34. Inline-Level Layout content area inline element inline box content area half-leading which is Strongly emphasized and which is
  • 35. Inline-Level Layout content area inline element inline box content area half-leading which is Strongly emphasized and which is baseline
  • 36. Inline box formating The containing block which is Strongly emphasized which is beijing oepn party is good
  • 38. Other Element Display Roles Inline-block: it has no breaks, but you can specific width and height on it display: none (totally hide the content, remove it from layout flow) about visibility: hide (do not display the content, but still take effect in layout flow)
  • 44. Control the layout Floating Layout Absolute positioning Left, right float Fixed positioning Clear float z-index Shrink to fit Table Layout Positioning Layout Fixed table layout Static positioning Automatic table layout Relative positioning
  • 45. Values and Units Color Values Length Values #RRGGBB Absolute length units #RGB Inches (in) rgb(rrr.rr%, ggg.gg%, Centimeters (cm) bbb.bb%) Millimeters (mm) rgb(rrr, ggg, bbb) Points (pt) 12pt = 1in keyword (black, blue ...) Picas (pc)
  • 46. Values and Units Length Values Relative length units em-height (em) x-height (ex) Pixels (px) Percentage Values (%)
  • 47. Agenda XHTML & CSS CSS selector Visual formatting & models Basic sample Advanced sample Tricks and hacks
  • 48. CSS basic example Style for font (size, weight, color, style, family) Style for link love/hate rollover (spry) Style for float image and clear Style for background
  • 49. Agenda XHTML & CSS CSS selector Visual formatting & models Basic sample Advanced sample Tricks and hacks
  • 50. CSS Advanced example Image button rounded corner horizontal menu fixed width css tooltip mountain corner slide door tab 4 wrapped bg images 4 corner images css rounded corner
  • 51. Agenda XHTML & CSS CSS selector Visual formatting & models Basic sample Advanced sample Tricks and hacks
  • 52. Hacks and Tricks Most hacks is for IE Tricks for IE Star hack (6) min-width/width(6) Underscore hack (7) <!--[if lte IE 7]> !important (6) <![endif]--> > child selector (-5, -6) property selector has-layout? zoom: 1
  • 53. You are coming a long way, baby

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n