SlideShare ist ein Scribd-Unternehmen logo
1 von 111
CSS
CASCADE
A quick
background
on CSS rules
CSS rules tell browsers how to
 render elements in an HTML
          document.

 h2
 {
      color: blue;
      margin: 1em;
 }
The selector "selects" the
    elements in an HTML
document that are to be styled.

 h2      Selector
 {
      color: blue;
      margin: 1em;
 }
The declaration tells a
    browser how to style the
           element.

h2
{
      color: blue;       Declaration
      margin: 1em;
}
The property is the aspect of
        that element that you are
            choosing to style.

           h2
           {
Property        color: blue;
                margin: 1em;
           }
The value is the exact style
  you wish to set for the
        property.

h2
{
     color: blue;    Value
     margin: 1em;
}
Types of
style sheets
HTML documents may have
three types of style sheets
      applied to them.
Browser style sheets
Browsers apply style sheets to
all web documents. These are
    referred to as a "default"
      browser style sheet.
User style sheets
Most modern browsers allow
users to apply their own style
 sheets within the browser.
Author style sheets
Web authors can apply one or
  more style sheets to an
     HTML document.
Author styles
There are three methods that
 authors can use to add CSS
 styles to an HTML document
Inline styles are applied to
elements in the HTML code
  using the style attribute.
         Inline style using style attribute
<body>
<h2 style=“color: red;”>
    Heading here
</h2>
<p>
Header styles are placed in
 the head of the document
  using the style element
        Header style inside <style> element
<head>
<title>Document title</titl
<style type="text/css" medi
h2 { color: blue; }
</style>
External style sheets are
 applied using the link or
        @import.
        External style using link element
<title>Document title</titl
<link rel="stylesheet"
href=”my-styles.css”
type=”text/css"
media="screen” />
CSS rule
overload!
Browsers have to deal with
CSS rules coming from the
browser, user and author
      style sheets.
Browsers also have to deal
 with CSS rules coming from
different types of author style
sheets (external, header and
             inline)
At some point, Browsers
have to deal with CSS rules
       that conflict.
What does
“conflict”
 mean?
Conflict is where more than
 one CSS rule refers to the
same element and property.

 h2 { color: blue; }
 h2 { color: red; }


    Conflicting CSS rules
Conflict can occur between
CSS rules in different types
      of style sheets.
                      Browse style sheet
h2 { color: blue; }


                      Author style sheet
h2 { color: red; }
Conflict can occur between
CSS rules in within the one or
 more author style sheets.
                       Author style sheet 1
 h2 { color: blue; }


                       Author style sheet 2
 h2 { color: red; }
 h2 { color: green; }
So which
CSS rules
 “win”?
There are four steps
to determine which CSS rules
  will “win” (be applied to an
        HTML document)
Step 1
Gather all the declarations
that apply to an element and
property from browser, author
    and user style sheets
For example, find any
declarations that matches:

       element = h2
     property = color
Gathered declarations
Browser style sheet   h2 { color: black; }




   User style sheet   h2 { color: green; }




Author style sheets   h2 { color: blue; }
                      #nav h2 { color: lime; }
If there are declarations from
more than one of these three
  sources, proceed to step 2.
Step 2
Sort the gathered declarations
according to origin (browser,
author, user style sheets) and
   importance (normal or
          !important).
What is
!important?
Authors can assign
    “!important” to any
        declaration.

h2 { color: red !important;}

                 !important
"!important" declarations
override normal declarations
  (Normal declarations are
    declarations that do not
      contain !important).
So, how are
declarations
  sorted?
From lowest to highest priority
1   browser styles
2   normal declarations in user style sheet
3   normal declarations in author style sheet
4   !important declarations in author style sheet
5   !important declarations in user style sheet
1. Browser styles
Browser style sheet   h2 { color: black; }


                          If no other declarations exist,
                          browser declarations win
   User style sheet




Author style sheets
2. Normal user styles
  Browser style sheet   h2 { color: black; }
Normal user declarations beat
browser declarations

     User style sheet   h2 { color: green; }




  Author style sheets
3. Normal author styles
  Browser style sheet   h2 { color: black; }

Normal author declarations beat browser
declarations and normal user declarations

     User style sheet   h2 { color: green; }




  Author style sheets   h2 { color: blue; }
4. !important author styles
  Browser style sheet   h2 { color: black; }

!important author declarations beat
all normal declarations

     User style sheet   h2 { color: green; }




  Author style sheets   h2 { color: blue; }
                        h2 { color: lime !important; }
5. !important user styles
   Browser style sheet   h2 { color: black; }

!important user declarations beat !important author
declarations and all normal declarations

      User style sheet   h2 { color: green; }
                         h2 { color: red !important;}



                         h2 { color: blue; }
   Author style sheets
                         h2 { color: lime !important; }
But what if two declarations
  have the same origin
     or importance?
Two matching declarations
  Browser style sheet    h2 { color: black; }




      User style sheet   h2 { color: green; }

Two declarations with the same origin and importance


   Author style sheets   h2 { color: blue; }
                         h2 { color: lime; }
If declarations have the same
  origin or importance then
      proceed to Step 3.
Step 3
If declarations have the same
 origin or importance then the
declaration’s selectors need
   to be scored, to see which
      declaration will “win”.
Selectors

#nav h2 { color: blue; }
h2.intro { color: red; }

 Selectors
Four scores are concatenated
(linked together as a chain) to
      create a final score.

           a,b,c,d
This score is referred to as a
   selector’s specificity.
So how is
 specificity
calculated?
A. Is there an inline style?



          <h2 style=“color: red;”>
                 This is a heading
          </h2>
a = 1 x inline styles
b = 0 x ID<p>
c = 0 x classes Here is a paragraph of
d = 0 x element
Specificity = 1,0,0,0
B. Count the number of IDs
             in the selectors.


         #nav { color: red; }

a = 0 x inline styles
b = 1 x ID
c = 0 x classes
d = 0 x element
Specificity = 0,1,0,0
C. Count the number of
           classes, attributes and
               pseudo-classes.

         .main { color: red; }

a = 0 x inline styles
b = 0 x ID
c = 1 x classes
d = 0 x element
Specificity = 0,0,1,0
D. Count the number of
        element names or pseudo-
                elements.

         h2 { color: red; }

a = 0 x inline styles
b = 0 x ID
c = 0 x classes
d = 1 x element
Specificity = 0,0,0,1
A note on
concatenation
“A” will always beat “B”, which
will always beat “C”, which will
        always beat “D”.
No matter how many IDs are
used in a selector, an inline
   style will always win.
 (unless !important is used within the ID’s declaration)
External style sheets    #one #two #three #four #five
   and header styles     #six #seven #eight #nine #ten
      (Author styles)    { color: green; }




HTML document with       <h2 style=“color: purple;”>
       inline styles
     (Author styles)

The highlighted style wins due to specificity -
1,0,0,0 beats 0,10,0,0
No matter how many classes
are applied to a selector, an ID
        can easily win
External style sheets   .one .two .three .four .five
   and header styles    .six .seven .eight .nine .ten
      (Author styles)   { color: green; }

                        #nav { color: lime; }


The highlighted selector wins due to specificity -
0,1,0,0 beats 0,0,10,0
No matter how many elements
  are applied to a selector, a
     class can easily win.
External style sheets   div div div div div form
   and header styles    fieldset div label span
      (Author styles)   { color: green; }

                        .intro { color: lime; }


The highlighted selector wins due to specificity -
0,0,1,0 beats 0,0,0,10
Complex
examples of
 specificity
ID and element

         #nav h2 { color: red; }


a = 0 x inline styles
b = 1 x ID (#nav)
c = 0 x classes
d = 1 x element (h2)
Specificity = 0,1,0,1
Element and class

         h2.intro { color: red; }


a = 0 x inline styles
b = 0 x ID
c = 1 x classes (.intro)
d = 1 x element (h2)
Specificity = 0,0,1,1
ID, elements and pseudo-class

        #nav ul li a:hover { color:


a = 0 x inline styles
b = 1 x ID (#nav)
c = 1 x pseudo-class (:hover)
d = 3 x elements (ul, li, a)
Specificity = 0,1,1,3
Element and pseudo-element

         p:first-line { color: green


a = 0 x inline styles
b = 0 x ID
c = 0 x classes
d = 2 x element (p) and pseudo-element (:first-line)
Specificity = 0,0,0,2
Element and attribute selector

          h2[title=“intro”] { color:


a = 0 x inline styles
b = 0 x ID
c = 1 x attribute selector ([title=“intro”])
d = 1 x element (h2)
Specificity = 0,0,1,1
What if there
  is still no
clear winner?
Selectors with same specificity

         #nav h2 { color: red; }
         #nav h2 { color: green; }


Specificity = 0,1,0,1
If there is still no clear winner
     then proceed to Step 4.
Step 4
If two declarations have the
 same importance, origin and
specificity, the latter specified
        declaration wins
Equal-weight declarations

         #nav h2 { color: green; }
         #nav h2 { color: red; }


The second declaration wins
as it is written after the first.
And now…
a guessing
   game
Exercise 1
browser, user, author
Part 1: Which one wins?
Browser style sheet    h2 { color: black; }




    User style sheet    h2 { color: green; }




External style sheets
   and header styles
      (Author styles)


HTML document with
       inline styles
     (Author styles)
Browser style sheet   h2 { color: black; }




    User style sheet   h2 { color: green; }


Normal user declarations beats browser
declarations due to origin
External style sheets
   and header styles
     (Author styles)


HTML document with
       inline styles
     (Author styles)
Part 2: Which one wins?
Browser style sheet    h2 { color: black; }




    User style sheet    h2 { color: green; }




External style sheets   h2 { color: blue; }
   and header styles
      (Author styles)


HTML document with
       inline styles
     (Author styles)
Browser style sheet    h2 { color: black; }




    User style sheet    h2 { color: green; }




External style sheets   h2 { color: blue; }
   and header styles
      (Author styles)
Normal author declarations beat browser and
normal user declarations due to origin
HTML document with
        inline styles
      (Author styles)
Part 3: Which one wins?
Browser style sheet    h2 { color: black; }




    User style sheet    h2 { color: green; }




External style sheets   h2 { color: blue; }
   and header styles
      (Author styles)


HTML document with      <h2 style=“color: purple;”>
       inline styles
     (Author styles)
Browser style sheet    h2 { color: black; }




     User style sheet     h2 { color: green; }
Normal inline declarations beat normal
external and header declarations due to
specificity: 1,0,0,0 beats 0,0,0,1

External style sheets   h2 { color: blue; }
   and header styles
      (Author styles)


HTML document with      <h2 style=“color: purple;”>
       inline styles
     (Author styles)
Part 4: Which one wins?
Browser style sheet    h2 { color: black; }




    User style sheet    h2 { color: green; }




External style sheets   h2 { color: blue; }
   and header styles    h2 { color: lime !important; }
      (Author styles)


HTML document with      <h2 style=“color: purple;”>
       inline styles
     (Author styles)
Browser style sheet    h2 { color: black; }




    User style sheet    h2 { color: green; }

!important author declarations beat normal
browser, user and author declarations

External style sheets   h2 { color: blue; }
   and header styles    h2 { color: lime !important; }
      (Author styles)


HTML document with      <h2 style=“color: purple;”>
       inline styles
     (Author styles)
Part 5: Which one wins?
Browser style sheet    h2 { color: black; }




    User style sheet    h2 { color: green; }




External style sheets   h2 { color: blue; }
   and header styles    h2 { color: lime !important; }
      (Author styles)


HTML document with      <h2 style=“color: purple
       inline styles    !important;”>
     (Author styles)
Browser style sheet    h2 { color: black; }




     User style sheet
!important inline authorh2 { color: beat
                          declarations green; }
!important external author and header declarations
due to specificity: 1,0,0,0 beats 0,0,0,1

External style sheets   h2 { color: blue; }
   and header styles    h2 { color: lime !important; }
      (Author styles)


HTML document with      <h2 style=“color: purple
       inline styles    !important;”>
     (Author styles)
Part 6: Which one wins?
Browser style sheet    h2 { color: black; }




    User style sheet    h2 { color: green; }
                        h2 { color: gray !important; }



External style sheets   h2 { color: blue; }
   and header styles    h2 { color: lime !important; }
      (Author styles)


HTML document with      <h2 style=“color: purple
       inline styles    !important;”>
     (Author styles)
Browser style sheet
!important user declarations beat !important }
                         h2 { color: black;
author declarations (regardless of whether they
are external, header or inline)

    User style sheet    h2 { color: green; }
                        h2 { color: gray !important; }



External style sheets   h2 { color: blue; }
   and header styles    h2 { color: lime !important; }
      (Author styles)


HTML document with      <h2 style=“color: purple
       inline styles    !important;”>
     (Author styles)
Exercise 2
author external, header
    and inline CSS
Part 1: Which one wins?
External style sheets   h2.news { color: #eee; }
   and header styles    h2 { color: blue; }
      (Author styles)
The highlighted declaration wins due to
specificity - 0,0,1,1 beats 0,0,0,1



External style sheets   h2.news { color: #eee; }
   and header styles    h2 { color: blue; }
      (Author styles)
Part 2: Which one wins?
External style sheets   h2.news { color: #eee; }
   and header styles    h2 { color: blue; }
      (Author styles)   h2.news { color: green; }
The highlighted declaration has the same
specificity as the first declaration (0,0,1,1).
However, as it is written later, it wins!

External style sheets     h2.news { color: #eee; }
   and header styles      h2 { color: blue; }
      (Author styles)     h2.news { color: green; }
Part 3: Which one wins?
External style sheets   #nav h2 { color: lime; }
   and header styles    h2.news { color: #eee; }
      (Author styles)   h2 { color: blue; }
                        h2.news { color: green; }
The highlighted selector wins due to specificity -
0,1,0,1 beats 0,0,1,1 and 0,0,0,1


External style sheets   #nav h2 { color: lime; }
   and header styles    h2.news { color: #eee; }
      (Author styles)   h2 { color: blue; }
                        h2.news { color: green; }
Part 4: Which one wins?
External style sheets   #nav h2 { color: lime; }
   and header styles    h2.news { color: #eee; }
      (Author styles)   h2 { color: blue; }
                        h2.news { color: green; }
                        div#nav h2 { color: lime; }
The highlighted selector wins due to specificity -
0,1,0,2 beats 0,1,0,1 and 0,0,1,1 and 0,0,0,1


External style sheets   #nav h2 { color: lime; }
   and header styles    h2.news { color: #eee; }
      (Author styles)   h2 { color: blue; }
                        h2.news { color: green; }
                        div#nav h2 { color: lime; }
We’re done!

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

CSS Foundations, pt 2
CSS Foundations, pt 2CSS Foundations, pt 2
CSS Foundations, pt 2
 
Java script
Java scriptJava script
Java script
 
CSS Part I
CSS Part ICSS Part I
CSS Part I
 
Css ppt - Cascading Style Sheets
Css ppt - Cascading Style SheetsCss ppt - Cascading Style Sheets
Css ppt - Cascading Style Sheets
 
Web Typography
Web TypographyWeb Typography
Web Typography
 
DIWE - Coding HTML for Basic Web Designing
DIWE - Coding HTML for Basic Web DesigningDIWE - Coding HTML for Basic Web Designing
DIWE - Coding HTML for Basic Web Designing
 
Javascript
JavascriptJavascript
Javascript
 
Css
CssCss
Css
 
presentation
presentationpresentation
presentation
 
Cssxcountry slides
Cssxcountry slidesCssxcountry slides
Cssxcountry slides
 
The Ring programming language version 1.4 book - Part 13 of 30
The Ring programming language version 1.4 book - Part 13 of 30The Ring programming language version 1.4 book - Part 13 of 30
The Ring programming language version 1.4 book - Part 13 of 30
 
Java script final presentation
Java script final presentationJava script final presentation
Java script final presentation
 
Web Layout
Web LayoutWeb Layout
Web Layout
 
FYBSC IT Web Programming Unit III Document Object
FYBSC IT Web Programming Unit III  Document ObjectFYBSC IT Web Programming Unit III  Document Object
FYBSC IT Web Programming Unit III Document Object
 
Javascript
JavascriptJavascript
Javascript
 
Lecture7
Lecture7Lecture7
Lecture7
 
HTML Foundations, pt 2
HTML Foundations, pt 2HTML Foundations, pt 2
HTML Foundations, pt 2
 
Span and Div tags in HTML
Span and Div tags in HTMLSpan and Div tags in HTML
Span and Div tags in HTML
 
Java script
Java scriptJava script
Java script
 
Towards an RDF Validation Language based on Regular Expression Derivatives
Towards an RDF Validation Language based on Regular Expression DerivativesTowards an RDF Validation Language based on Regular Expression Derivatives
Towards an RDF Validation Language based on Regular Expression Derivatives
 

Ähnlich wie CSS CASCADE

Introduction to css by programmerblog.net
Introduction to css by programmerblog.netIntroduction to css by programmerblog.net
Introduction to css by programmerblog.netProgrammer Blog
 
Make Css easy : easy tips for css
Make Css easy : easy tips for cssMake Css easy : easy tips for css
Make Css easy : easy tips for cssshabab shihan
 
An Introduction to Cascading Style Sheets (CSS3)
An Introduction to Cascading Style Sheets (CSS3)An Introduction to Cascading Style Sheets (CSS3)
An Introduction to Cascading Style Sheets (CSS3)Ardee Aram
 
Chapter 4a cascade style sheet css
Chapter 4a cascade style sheet cssChapter 4a cascade style sheet css
Chapter 4a cascade style sheet cssTesfaye Yenealem
 
Cascading Style Sheets - Part 01
Cascading Style Sheets - Part 01Cascading Style Sheets - Part 01
Cascading Style Sheets - Part 01Hatem Mahmoud
 
Introduction to CSS
Introduction to CSSIntroduction to CSS
Introduction to CSSNicole Ryan
 
css-presentation.ppt
css-presentation.pptcss-presentation.ppt
css-presentation.pptprathur68
 
CSS Overview and Examples
CSS Overview and ExamplesCSS Overview and Examples
CSS Overview and ExamplesMouli Kalakota
 
Web development chapter-3.ppt
Web development chapter-3.pptWeb development chapter-3.ppt
Web development chapter-3.pptssuserf3db48
 
Intro to CSS Selectors in Drupal
Intro to CSS Selectors in DrupalIntro to CSS Selectors in Drupal
Intro to CSS Selectors in Drupalcgmonroe
 

Ähnlich wie CSS CASCADE (20)

Introduction to css by programmerblog.net
Introduction to css by programmerblog.netIntroduction to css by programmerblog.net
Introduction to css by programmerblog.net
 
Make Css easy : easy tips for css
Make Css easy : easy tips for cssMake Css easy : easy tips for css
Make Css easy : easy tips for css
 
An Introduction to Cascading Style Sheets (CSS3)
An Introduction to Cascading Style Sheets (CSS3)An Introduction to Cascading Style Sheets (CSS3)
An Introduction to Cascading Style Sheets (CSS3)
 
WEB PROGRAMMING
WEB PROGRAMMINGWEB PROGRAMMING
WEB PROGRAMMING
 
Chapter 4a cascade style sheet css
Chapter 4a cascade style sheet cssChapter 4a cascade style sheet css
Chapter 4a cascade style sheet css
 
Cascading Style Sheets - Part 01
Cascading Style Sheets - Part 01Cascading Style Sheets - Part 01
Cascading Style Sheets - Part 01
 
Web 101
Web 101Web 101
Web 101
 
Introduction to CSS
Introduction to CSSIntroduction to CSS
Introduction to CSS
 
3. CSS
3. CSS3. CSS
3. CSS
 
CSS
CSSCSS
CSS
 
CSS Overview
CSS OverviewCSS Overview
CSS Overview
 
css-presentation.ppt
css-presentation.pptcss-presentation.ppt
css-presentation.ppt
 
CSS Overview and Examples
CSS Overview and ExamplesCSS Overview and Examples
CSS Overview and Examples
 
Web development chapter-3.ppt
Web development chapter-3.pptWeb development chapter-3.ppt
Web development chapter-3.ppt
 
Web - CSS 1.pptx
Web - CSS 1.pptxWeb - CSS 1.pptx
Web - CSS 1.pptx
 
Csstutorial
CsstutorialCsstutorial
Csstutorial
 
Css
CssCss
Css
 
Css
CssCss
Css
 
Intro to CSS Selectors in Drupal
Intro to CSS Selectors in DrupalIntro to CSS Selectors in Drupal
Intro to CSS Selectors in Drupal
 
CSS
CSS CSS
CSS
 

Mehr von Anuradha

Sql server 2012 - always on deep dive - bob duffy
Sql server 2012 - always on deep dive - bob duffySql server 2012 - always on deep dive - bob duffy
Sql server 2012 - always on deep dive - bob duffyAnuradha
 
J query visual-cheat-sheet-1.4.2
J query visual-cheat-sheet-1.4.2J query visual-cheat-sheet-1.4.2
J query visual-cheat-sheet-1.4.2Anuradha
 
Go Kiss The World
Go Kiss The WorldGo Kiss The World
Go Kiss The WorldAnuradha
 
CSS LINE HEIGHT
CSS LINE HEIGHTCSS LINE HEIGHT
CSS LINE HEIGHTAnuradha
 
CSS INHERITANCE
CSS INHERITANCECSS INHERITANCE
CSS INHERITANCEAnuradha
 
Insearchofmahatma 090802094040 Phpapp02
Insearchofmahatma 090802094040 Phpapp02Insearchofmahatma 090802094040 Phpapp02
Insearchofmahatma 090802094040 Phpapp02Anuradha
 
Presentation Alphabet
Presentation AlphabetPresentation Alphabet
Presentation AlphabetAnuradha
 
Dirtywindows
DirtywindowsDirtywindows
DirtywindowsAnuradha
 
Dear Son Dear Daughter Slide Show
Dear Son Dear Daughter Slide ShowDear Son Dear Daughter Slide Show
Dear Son Dear Daughter Slide ShowAnuradha
 
Beautiful Motivation
Beautiful MotivationBeautiful Motivation
Beautiful MotivationAnuradha
 
Great Leaders
Great LeadersGreat Leaders
Great LeadersAnuradha
 
Six Keys To Success
Six Keys To SuccessSix Keys To Success
Six Keys To SuccessAnuradha
 
Friendship And Love
Friendship And LoveFriendship And Love
Friendship And LoveAnuradha
 
Dr Apj Kalam
Dr Apj KalamDr Apj Kalam
Dr Apj KalamAnuradha
 
Attitude Is Everything
Attitude Is EverythingAttitude Is Everything
Attitude Is EverythingAnuradha
 
Age Character Calculation
Age Character CalculationAge Character Calculation
Age Character CalculationAnuradha
 

Mehr von Anuradha (20)

Sql server 2012 - always on deep dive - bob duffy
Sql server 2012 - always on deep dive - bob duffySql server 2012 - always on deep dive - bob duffy
Sql server 2012 - always on deep dive - bob duffy
 
J query visual-cheat-sheet-1.4.2
J query visual-cheat-sheet-1.4.2J query visual-cheat-sheet-1.4.2
J query visual-cheat-sheet-1.4.2
 
Inspiration
InspirationInspiration
Inspiration
 
Peace Now
Peace NowPeace Now
Peace Now
 
Go Kiss The World
Go Kiss The WorldGo Kiss The World
Go Kiss The World
 
CSS LINE HEIGHT
CSS LINE HEIGHTCSS LINE HEIGHT
CSS LINE HEIGHT
 
CSS INHERITANCE
CSS INHERITANCECSS INHERITANCE
CSS INHERITANCE
 
Insearchofmahatma 090802094040 Phpapp02
Insearchofmahatma 090802094040 Phpapp02Insearchofmahatma 090802094040 Phpapp02
Insearchofmahatma 090802094040 Phpapp02
 
Mahatma
MahatmaMahatma
Mahatma
 
Presentation Alphabet
Presentation AlphabetPresentation Alphabet
Presentation Alphabet
 
Dirtywindows
DirtywindowsDirtywindows
Dirtywindows
 
Dear Son Dear Daughter Slide Show
Dear Son Dear Daughter Slide ShowDear Son Dear Daughter Slide Show
Dear Son Dear Daughter Slide Show
 
Beautiful Motivation
Beautiful MotivationBeautiful Motivation
Beautiful Motivation
 
Great Leaders
Great LeadersGreat Leaders
Great Leaders
 
A Present
A PresentA Present
A Present
 
Six Keys To Success
Six Keys To SuccessSix Keys To Success
Six Keys To Success
 
Friendship And Love
Friendship And LoveFriendship And Love
Friendship And Love
 
Dr Apj Kalam
Dr Apj KalamDr Apj Kalam
Dr Apj Kalam
 
Attitude Is Everything
Attitude Is EverythingAttitude Is Everything
Attitude Is Everything
 
Age Character Calculation
Age Character CalculationAge Character Calculation
Age Character Calculation
 

Kürzlich hochgeladen

QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Digital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentDigital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentMahmoud Rabie
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sectoritnewsafrica
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Nikki Chapple
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Mark Simos
 
Kuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialKuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialJoão Esperancinha
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Karmanjay Verma
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFMichael Gough
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 

Kürzlich hochgeladen (20)

QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Digital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentDigital Tools & AI in Career Development
Digital Tools & AI in Career Development
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
 
Kuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialKuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorial
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDF
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 

CSS CASCADE

  • 3. CSS rules tell browsers how to render elements in an HTML document. h2 { color: blue; margin: 1em; }
  • 4. The selector "selects" the elements in an HTML document that are to be styled. h2 Selector { color: blue; margin: 1em; }
  • 5. The declaration tells a browser how to style the element. h2 { color: blue; Declaration margin: 1em; }
  • 6. The property is the aspect of that element that you are choosing to style. h2 { Property color: blue; margin: 1em; }
  • 7. The value is the exact style you wish to set for the property. h2 { color: blue; Value margin: 1em; }
  • 9. HTML documents may have three types of style sheets applied to them.
  • 10. Browser style sheets Browsers apply style sheets to all web documents. These are referred to as a "default" browser style sheet.
  • 11. User style sheets Most modern browsers allow users to apply their own style sheets within the browser.
  • 12. Author style sheets Web authors can apply one or more style sheets to an HTML document.
  • 14. There are three methods that authors can use to add CSS styles to an HTML document
  • 15. Inline styles are applied to elements in the HTML code using the style attribute. Inline style using style attribute <body> <h2 style=“color: red;”> Heading here </h2> <p>
  • 16. Header styles are placed in the head of the document using the style element Header style inside <style> element <head> <title>Document title</titl <style type="text/css" medi h2 { color: blue; } </style>
  • 17. External style sheets are applied using the link or @import. External style using link element <title>Document title</titl <link rel="stylesheet" href=”my-styles.css” type=”text/css" media="screen” />
  • 19. Browsers have to deal with CSS rules coming from the browser, user and author style sheets.
  • 20. Browsers also have to deal with CSS rules coming from different types of author style sheets (external, header and inline)
  • 21. At some point, Browsers have to deal with CSS rules that conflict.
  • 23. Conflict is where more than one CSS rule refers to the same element and property. h2 { color: blue; } h2 { color: red; } Conflicting CSS rules
  • 24. Conflict can occur between CSS rules in different types of style sheets. Browse style sheet h2 { color: blue; } Author style sheet h2 { color: red; }
  • 25. Conflict can occur between CSS rules in within the one or more author style sheets. Author style sheet 1 h2 { color: blue; } Author style sheet 2 h2 { color: red; } h2 { color: green; }
  • 26. So which CSS rules “win”?
  • 27. There are four steps to determine which CSS rules will “win” (be applied to an HTML document)
  • 29. Gather all the declarations that apply to an element and property from browser, author and user style sheets
  • 30. For example, find any declarations that matches: element = h2 property = color
  • 31. Gathered declarations Browser style sheet h2 { color: black; } User style sheet h2 { color: green; } Author style sheets h2 { color: blue; } #nav h2 { color: lime; }
  • 32. If there are declarations from more than one of these three sources, proceed to step 2.
  • 34. Sort the gathered declarations according to origin (browser, author, user style sheets) and importance (normal or !important).
  • 36. Authors can assign “!important” to any declaration. h2 { color: red !important;} !important
  • 37. "!important" declarations override normal declarations (Normal declarations are declarations that do not contain !important).
  • 39. From lowest to highest priority 1 browser styles 2 normal declarations in user style sheet 3 normal declarations in author style sheet 4 !important declarations in author style sheet 5 !important declarations in user style sheet
  • 40. 1. Browser styles Browser style sheet h2 { color: black; } If no other declarations exist, browser declarations win User style sheet Author style sheets
  • 41. 2. Normal user styles Browser style sheet h2 { color: black; } Normal user declarations beat browser declarations User style sheet h2 { color: green; } Author style sheets
  • 42. 3. Normal author styles Browser style sheet h2 { color: black; } Normal author declarations beat browser declarations and normal user declarations User style sheet h2 { color: green; } Author style sheets h2 { color: blue; }
  • 43. 4. !important author styles Browser style sheet h2 { color: black; } !important author declarations beat all normal declarations User style sheet h2 { color: green; } Author style sheets h2 { color: blue; } h2 { color: lime !important; }
  • 44. 5. !important user styles Browser style sheet h2 { color: black; } !important user declarations beat !important author declarations and all normal declarations User style sheet h2 { color: green; } h2 { color: red !important;} h2 { color: blue; } Author style sheets h2 { color: lime !important; }
  • 45. But what if two declarations have the same origin or importance?
  • 46. Two matching declarations Browser style sheet h2 { color: black; } User style sheet h2 { color: green; } Two declarations with the same origin and importance Author style sheets h2 { color: blue; } h2 { color: lime; }
  • 47. If declarations have the same origin or importance then proceed to Step 3.
  • 49. If declarations have the same origin or importance then the declaration’s selectors need to be scored, to see which declaration will “win”.
  • 50. Selectors #nav h2 { color: blue; } h2.intro { color: red; } Selectors
  • 51. Four scores are concatenated (linked together as a chain) to create a final score. a,b,c,d
  • 52. This score is referred to as a selector’s specificity.
  • 53. So how is specificity calculated?
  • 54. A. Is there an inline style? <h2 style=“color: red;”> This is a heading </h2> a = 1 x inline styles b = 0 x ID<p> c = 0 x classes Here is a paragraph of d = 0 x element Specificity = 1,0,0,0
  • 55. B. Count the number of IDs in the selectors. #nav { color: red; } a = 0 x inline styles b = 1 x ID c = 0 x classes d = 0 x element Specificity = 0,1,0,0
  • 56. C. Count the number of classes, attributes and pseudo-classes. .main { color: red; } a = 0 x inline styles b = 0 x ID c = 1 x classes d = 0 x element Specificity = 0,0,1,0
  • 57. D. Count the number of element names or pseudo- elements. h2 { color: red; } a = 0 x inline styles b = 0 x ID c = 0 x classes d = 1 x element Specificity = 0,0,0,1
  • 59. “A” will always beat “B”, which will always beat “C”, which will always beat “D”.
  • 60. No matter how many IDs are used in a selector, an inline style will always win. (unless !important is used within the ID’s declaration)
  • 61. External style sheets #one #two #three #four #five and header styles #six #seven #eight #nine #ten (Author styles) { color: green; } HTML document with <h2 style=“color: purple;”> inline styles (Author styles) The highlighted style wins due to specificity - 1,0,0,0 beats 0,10,0,0
  • 62. No matter how many classes are applied to a selector, an ID can easily win
  • 63. External style sheets .one .two .three .four .five and header styles .six .seven .eight .nine .ten (Author styles) { color: green; } #nav { color: lime; } The highlighted selector wins due to specificity - 0,1,0,0 beats 0,0,10,0
  • 64. No matter how many elements are applied to a selector, a class can easily win.
  • 65. External style sheets div div div div div form and header styles fieldset div label span (Author styles) { color: green; } .intro { color: lime; } The highlighted selector wins due to specificity - 0,0,1,0 beats 0,0,0,10
  • 67. ID and element #nav h2 { color: red; } a = 0 x inline styles b = 1 x ID (#nav) c = 0 x classes d = 1 x element (h2) Specificity = 0,1,0,1
  • 68. Element and class h2.intro { color: red; } a = 0 x inline styles b = 0 x ID c = 1 x classes (.intro) d = 1 x element (h2) Specificity = 0,0,1,1
  • 69. ID, elements and pseudo-class #nav ul li a:hover { color: a = 0 x inline styles b = 1 x ID (#nav) c = 1 x pseudo-class (:hover) d = 3 x elements (ul, li, a) Specificity = 0,1,1,3
  • 70. Element and pseudo-element p:first-line { color: green a = 0 x inline styles b = 0 x ID c = 0 x classes d = 2 x element (p) and pseudo-element (:first-line) Specificity = 0,0,0,2
  • 71. Element and attribute selector h2[title=“intro”] { color: a = 0 x inline styles b = 0 x ID c = 1 x attribute selector ([title=“intro”]) d = 1 x element (h2) Specificity = 0,0,1,1
  • 72. What if there is still no clear winner?
  • 73. Selectors with same specificity #nav h2 { color: red; } #nav h2 { color: green; } Specificity = 0,1,0,1
  • 74. If there is still no clear winner then proceed to Step 4.
  • 76. If two declarations have the same importance, origin and specificity, the latter specified declaration wins
  • 77. Equal-weight declarations #nav h2 { color: green; } #nav h2 { color: red; } The second declaration wins as it is written after the first.
  • 80. Part 1: Which one wins?
  • 81. Browser style sheet h2 { color: black; } User style sheet h2 { color: green; } External style sheets and header styles (Author styles) HTML document with inline styles (Author styles)
  • 82. Browser style sheet h2 { color: black; } User style sheet h2 { color: green; } Normal user declarations beats browser declarations due to origin External style sheets and header styles (Author styles) HTML document with inline styles (Author styles)
  • 83. Part 2: Which one wins?
  • 84. Browser style sheet h2 { color: black; } User style sheet h2 { color: green; } External style sheets h2 { color: blue; } and header styles (Author styles) HTML document with inline styles (Author styles)
  • 85. Browser style sheet h2 { color: black; } User style sheet h2 { color: green; } External style sheets h2 { color: blue; } and header styles (Author styles) Normal author declarations beat browser and normal user declarations due to origin HTML document with inline styles (Author styles)
  • 86. Part 3: Which one wins?
  • 87. Browser style sheet h2 { color: black; } User style sheet h2 { color: green; } External style sheets h2 { color: blue; } and header styles (Author styles) HTML document with <h2 style=“color: purple;”> inline styles (Author styles)
  • 88. Browser style sheet h2 { color: black; } User style sheet h2 { color: green; } Normal inline declarations beat normal external and header declarations due to specificity: 1,0,0,0 beats 0,0,0,1 External style sheets h2 { color: blue; } and header styles (Author styles) HTML document with <h2 style=“color: purple;”> inline styles (Author styles)
  • 89. Part 4: Which one wins?
  • 90. Browser style sheet h2 { color: black; } User style sheet h2 { color: green; } External style sheets h2 { color: blue; } and header styles h2 { color: lime !important; } (Author styles) HTML document with <h2 style=“color: purple;”> inline styles (Author styles)
  • 91. Browser style sheet h2 { color: black; } User style sheet h2 { color: green; } !important author declarations beat normal browser, user and author declarations External style sheets h2 { color: blue; } and header styles h2 { color: lime !important; } (Author styles) HTML document with <h2 style=“color: purple;”> inline styles (Author styles)
  • 92. Part 5: Which one wins?
  • 93. Browser style sheet h2 { color: black; } User style sheet h2 { color: green; } External style sheets h2 { color: blue; } and header styles h2 { color: lime !important; } (Author styles) HTML document with <h2 style=“color: purple inline styles !important;”> (Author styles)
  • 94. Browser style sheet h2 { color: black; } User style sheet !important inline authorh2 { color: beat declarations green; } !important external author and header declarations due to specificity: 1,0,0,0 beats 0,0,0,1 External style sheets h2 { color: blue; } and header styles h2 { color: lime !important; } (Author styles) HTML document with <h2 style=“color: purple inline styles !important;”> (Author styles)
  • 95. Part 6: Which one wins?
  • 96. Browser style sheet h2 { color: black; } User style sheet h2 { color: green; } h2 { color: gray !important; } External style sheets h2 { color: blue; } and header styles h2 { color: lime !important; } (Author styles) HTML document with <h2 style=“color: purple inline styles !important;”> (Author styles)
  • 97. Browser style sheet !important user declarations beat !important } h2 { color: black; author declarations (regardless of whether they are external, header or inline) User style sheet h2 { color: green; } h2 { color: gray !important; } External style sheets h2 { color: blue; } and header styles h2 { color: lime !important; } (Author styles) HTML document with <h2 style=“color: purple inline styles !important;”> (Author styles)
  • 98. Exercise 2 author external, header and inline CSS
  • 99. Part 1: Which one wins?
  • 100. External style sheets h2.news { color: #eee; } and header styles h2 { color: blue; } (Author styles)
  • 101. The highlighted declaration wins due to specificity - 0,0,1,1 beats 0,0,0,1 External style sheets h2.news { color: #eee; } and header styles h2 { color: blue; } (Author styles)
  • 102. Part 2: Which one wins?
  • 103. External style sheets h2.news { color: #eee; } and header styles h2 { color: blue; } (Author styles) h2.news { color: green; }
  • 104. The highlighted declaration has the same specificity as the first declaration (0,0,1,1). However, as it is written later, it wins! External style sheets h2.news { color: #eee; } and header styles h2 { color: blue; } (Author styles) h2.news { color: green; }
  • 105. Part 3: Which one wins?
  • 106. External style sheets #nav h2 { color: lime; } and header styles h2.news { color: #eee; } (Author styles) h2 { color: blue; } h2.news { color: green; }
  • 107. The highlighted selector wins due to specificity - 0,1,0,1 beats 0,0,1,1 and 0,0,0,1 External style sheets #nav h2 { color: lime; } and header styles h2.news { color: #eee; } (Author styles) h2 { color: blue; } h2.news { color: green; }
  • 108. Part 4: Which one wins?
  • 109. External style sheets #nav h2 { color: lime; } and header styles h2.news { color: #eee; } (Author styles) h2 { color: blue; } h2.news { color: green; } div#nav h2 { color: lime; }
  • 110. The highlighted selector wins due to specificity - 0,1,0,2 beats 0,1,0,1 and 0,0,1,1 and 0,0,0,1 External style sheets #nav h2 { color: lime; } and header styles h2.news { color: #eee; } (Author styles) h2 { color: blue; } h2.news { color: green; } div#nav h2 { color: lime; }