SlideShare ist ein Scribd-Unternehmen logo
1 von 94
Downloaden Sie, um offline zu lesen
1
2
3
4
5
6
6 1
 +    = holy crap




                    7
8
9
10
11
12
13
14
15
I hope you know HTML




                       16
The most important
 thing you need to
      know...


                     17
18
The Box Model
Margin                10

     Border           5

         Padding      10




10   5        10   200 x 80   10   5   10




                      10

                      5

                      10




                                            19
width
          padding-left
         padding-right
            border-left
+         border-right
    Calculated Width

                          20
Width = 250px
Margin                10

     Border           5

         Padding      10




10   5        10   200 x 80   10   5   10




                      10

                      5

                      10




                                            21
height
           padding-top
        padding-bottom
             border-top
+        border-bottom
    Calculated Height

                          22
Height = 130px
Margin                10

     Border           5

         Padding      10




10   5        10   200 x 80   10   5   10




                      10

                      5

                      10




                                            23
Block Level Elements
Parent Element


                 width:auto




  If no width declared all block
level elements within the parent
    element will be set to 100%.

                                   24
Block Level Elements
Parent Element


       width:200px




  If you declare a width...well
  your block level element will
 have that width, regardless of
       the parent element
                                  25
Absolute Elements
Parent Element
                                   well hello there


                 well hello there...the box expands




If you don’t specify a width, the
    box will expand with the
   content. It will expand until
 100% of the parent, then wrap.

                                                      26
Floated Elements
Parent Element
                                          well hello there


                        well hello there...the box expands




         Mimics the behavior of
          positioned elements.
             Doesn’t depend on
             relative positioning
                                                             27
Rule of Thumb
Specify the width on:
  • floated elements
  • positioned elements either
    fixed or absolute



                                 28
Inline Elements
Parent Element

 well hello there
 well hello there...the box expands
 well hello there
 well hello there...the box expands




  Just really long, skinny boxes

                                      29
CSS Rule Set



               30
CSS Rule Set
Tells a browser how to render HTML boxes

Selector   Declaration Block



               Declaration           Declaration


               Property      Value   Property      Value

body       {   color :black ; padding:1em ; }




                                                           31
CSS Rule Set
Tells a browser how to render HTML elements

  Selector   Declaration Block



                 Declaration           Declaration


                 Property      Value   Property      Value

 body        {   color :black ; padding:1em ; }




                                                             32
Selector   Declaration Block



                Declaration           Declaration


                Property      Value   Property      Value

 body       {   color :black ; padding:1em ; }




Selector: “selects” an HTML
element that should be affected
by a rule set

                                                            33
Selector   Declaration Block



                Declaration           Declaration


                Property      Value   Property      Value

 body       {   color :black ; padding:1em ; }



Declaration Block: anything
between the curly brackets


                                                            34
Selector   Declaration Block



                Declaration           Declaration


                Property      Value   Property      Value

 body       {   color :black ; padding:1em ; }



Declaration: Tells the browser
how to draw any element on a
page that is selected

                                                            35
Selector   Declaration Block



                Declaration           Declaration


                Property      Value   Property      Value

 body       {   color :black ; padding:1em ; }



Property: The aspects of the
HTML element that you are
choosing to style.

                                                            36
Selector   Declaration Block



                Declaration           Declaration


                Property      Value   Property      Value

 body       {   color :black ; padding:1em ; }



Value: The exact style you want
to set for the property


                                                            37
All together now
Declarations can be grouped.

      p{
           margin: 10px;
           padding: 20px;
      }




                               38
All together now
Selectors can be grouped.

    h1, h2, h3 {
        padding:10px;
    }




                            39
CSS Shorthand



                40
Font
h1{
  font-family: Arial;
  font-size: 100%;
  font-style: normal;
  font-variant: small-caps;
  font-weight: bold;
  line-height:120%;
}



                              41
Font

h1{
  font: bold small-caps 100%/120% Arial;
}




                                           42
Font
      style      variant    size   line-height   font-family


font: bold    small-caps   100%     120%         Arial ;




                                                               43
Margin/Padding
 p{
     margin-top: 1px;
     margin-right: 2px;
     margin-bottom: 3px;
     margin-left: 4px;
     padding-top: 1px;
     padding-right: 2px;
     padding-bottom: 3px;
     padding-left: 4px;
 }


                            44
Margin/Padding
            T




     L            R




            B


margin: 1px 2px 3px 4px;
padding: 1px 2px 3px 4px;



                            45
Margin/Padding
          T   R   B   L

margin: 1px 2px 3px 4px;
padding: 1px 2px 3px 4px;




                            46
Margin/Padding
          T    R/L   B

margin: 1px 2px 3px 2px;
padding: 1px 2px 3px 2px;

         T/B   R/L

margin: 1px 2px 1px 2px;
padding: 1px 2px 1px 2px;




                            47
Margin/Padding
        T/R/B/L

margin: 1px 1px 1px 1px;
padding: 1px 1px 1px 1px;




                            48
Comments
/* Comment */

margin:   1px 2px 3px 4px;

/*padding: 1px 2px 3px 4px;*/




                                49
Document Tree



                50
<body>
  <div id="container">
    <h1>This is the document tree</h1>
    <p>Lorem ipsum dolor sit amet.</p>
    <p>Lorem ipsum <strong>dolor</strong>
        sit amet</p>
  </div>
  <div id="nav">
    <ul>
       <li>Item 1</li>
       <li>Item 2</li>
       <li>Item 3</li>
    </ul>
  </div>
</body>

                                            51
body


  div                div


h1 p p               ul


  em            li    li   li




                                52
body


       div                      div


    h1 p p                      ul


       em                  li    li   li


               Ancestor
Any element that’s connected but further
 up the document tree, no matter how
          many level higher.

                                           53
body


      div                      div


   h1 p p                      ul


      em                  li    li   li


             Descendant
Any element that’s connected but lower
down the document tree, no matter how
          many levels lower.

                                          54
body


         div                      div Parent


      h1 p p                      ul   Child

         em                  li   li   li


                    Parent
Element that is directly above and connected
    to an element in the document tree


                                               55
body


         div                      div Parent


      h1 p p                      ul   Child

         em                  li   li   li


                     Child
Element that is directly below and connected
    to an element in the document tree


                                               56
body


        div                      div


      h1 p p                     ul


        em                  li    li   li


                  Siblings
An element that shares the same parent with
             another element


                                              57
Specificity
Determines which CSS rule is applied to an
         element by a browser




                                             58
Basic Specificity

Inline Style > #ID > .Class > Element




                                        59
Selectors



            60
Type Selectors
        li{color: red;}

             body

  div                      div

h1 p p                     ul
  em                  li    li   li


                                      61
Class Selectors
        .red{color: red;}

                body

  div                       div

h1 p    p.red               ul
  em                   li    li   li.red


                                           62
Class + Type Selectors
           p.red{color: red;}

                   body

     div                       div

   h1 p    p.red                ul
     em                   li    li   li.red


                                              63
Rule of Thumb
Don’t use classes to style HTML elements to
          look like other elements

<div class="heading">Main Heading</div>

          .heading{
            font-weight: bold;
            font-size: 140%;
          }



                                              64
Rule of Thumb
Do HTML elements that already exist


     <h1>Main Heading</h1>


      h1{
        font-size: 140%;
      }



                                      65
Think before you class

1. Is there an existing HTML element that I
   can use instead?
2. Is there a class or ID further up the
   document tree that can be used?




                                              66
ID Selectors
        #nav{color: red;}

                body

  div                       div

h1 p    p.red          ul nav
                            #
  em                   li    li   li.red


                                           67
ID vs .class
ID’s
  • They are unique
  • Each element can only have one ID
  • Each page can only have one element
     with the same ID
  • ID’s have special browser functionality
  • Javascript loves ID’s

       <div id="nav header"></div>


                                              68
ID vs .class
Classes
 • They aren’t unique
 • The same class can be used
   on multiple elements
 • You can use multiple classes on the
   same element

    <div class="nav header"></div>


                                         69
Descendant Selectors
          p em{color: red;}

                  body

    div                       div

  h1 p    p.red          ul nav
                              #
    em                   li    li   li.red


                                             70
Universal Selectors
         * {color: red;}

                 body

   div                       div

 h1 p    p.red          ul nav
                             #
   em                   li    li   li.red


                                            71
Child Selectors
  div > em {color: red;}

                body

  div                       div

h1 p    p.red          ul nav em
                            #
  em                   li    li   li.red


                                           72
Adjacent Sibling
   Selectors
    h1 + p {color: red;}

                body

  div                       div

h1 p    p.red          ul nav em
                            #
  em                   li    li   li.red


                                           73
Attribute Selectors
       4 Types




                      74
Attribute Selectors
      Select based on the attribute

  <img src="image.png" width="100"
  height="100" title="Main Image"
  alt="Main Image"/>


img[title] { border: 1px solid #000; }
img[width] { border: 1px solid #000; }
img[alt]   { border: 1px solid #000; }



                                         75
Attribute Selectors
Select based on the attribute’s value

<img src="image.png" width="100"
height="100" title="Main Image"
alt="Main Image"/>


    img[src="image.png"] {
      border: 1px solid #000;
    }



                                        76
Attribute Selectors
Select based on the space separated
        instances of a value

<img src="image.png" width="100"
height="100" title="Main Image"
alt="Main Image"/>

    img[alt~="Main"] {
      border: 1px solid #000;
    }



                                      77
Attribute Selectors
Select based on the hyphen separated
         instances of a value

 <img src="image.png" width="100"
 height="100" title="Main Image"
 alt="Main Image"/>

     img[alt|="Main"] {
       border: 1px solid #000;
     }



                                       78
:Pseudo Classes



                  79
Most Common

      :link
   :visited
     :hover
    :active




              80
:first-child
li:first-child {color: red;}

                body

  div                       div

h1 p    p.red          ul nav em
                            #
  em                   li    li   li.red


                                           81
:first-line
       p:first-line {color: red;}



Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Vestibulum rutrum purus
non risus porttitor convallis. In vitae nulla
id felis.



                                                82
:before and :after
  p:before {content: “ extra stuff”}



Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Vestibulum rutrum purus
non risus porttitor convallis. In vitae nulla
id felis. extra stuff



                                                83
CSS3 Selectors



                 84
Most Common

      :link
   :visited
     :hover
    :active




              85
:first-child
li:first-child {color: red;}

                body

  div                       div

h1 p    p.red          ul nav em
                            #
  em                   li    li   li.red


                                           86
:first-line
       p:first-line {color: red;}



Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Vestibulum rutrum purus
non risus porttitor convallis. In vitae nulla
id felis.



                                                87
:before and :after
  p:before {content: “ extra stuff”}



Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Vestibulum rutrum purus
non risus porttitor convallis. In vitae nulla
id felis. extra stuff



                                                88
CSS 3
I shall now cheat...I’m also lazy



    http://www.css3.info/




                                    89
CSS Tricks



             90
• Absolute Positioning (z-index)
• Multi-Column Layouts with floats
• .clearfix
• Image Sprites
• Image Replacement
• Center align elements
• display:none vs visibility:hidden
• Multiple background images


                                      91
A Clean Stylesheet



                     92
?
http://twitter.com/killermoo

http://bermonpainter.com

http://facebook.com/bermon




                               93
Books



Designing with   Transcending CSS   CSS Mastery
Web Standards    Andy Clarke        Andy Budd
Jeffry Zeldman




                                                  94

Weitere ähnliche Inhalte

Ähnlich wie CSS in all its Glory

Lecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
Lecture 10 CSS part 2.pptxvvvvvvvvvvvvvvLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
Lecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
ZahouAmel1
 
Compass And Sass(Tim Riley)
Compass And Sass(Tim Riley)Compass And Sass(Tim Riley)
Compass And Sass(Tim Riley)
elliando dias
 

Ähnlich wie CSS in all its Glory (20)

Quarter 3_Lesson_One_CSSheets_Paddings.pdf
Quarter 3_Lesson_One_CSSheets_Paddings.pdfQuarter 3_Lesson_One_CSSheets_Paddings.pdf
Quarter 3_Lesson_One_CSSheets_Paddings.pdf
 
CSS3 Refresher
CSS3 RefresherCSS3 Refresher
CSS3 Refresher
 
Building Responsive Layouts
Building Responsive LayoutsBuilding Responsive Layouts
Building Responsive Layouts
 
Ppt ch06
Ppt ch06Ppt ch06
Ppt ch06
 
Ppt ch06
Ppt ch06Ppt ch06
Ppt ch06
 
The Future of CSS Layout
The Future of CSS LayoutThe Future of CSS Layout
The Future of CSS Layout
 
Getting to Grips with Firebug - Anthony Hortin - WordCamp Sydney
Getting to Grips with Firebug - Anthony Hortin - WordCamp SydneyGetting to Grips with Firebug - Anthony Hortin - WordCamp Sydney
Getting to Grips with Firebug - Anthony Hortin - WordCamp Sydney
 
Intro to HTML & CSS
Intro to HTML & CSSIntro to HTML & CSS
Intro to HTML & CSS
 
Web Layout
Web LayoutWeb Layout
Web Layout
 
Css Essential
Css EssentialCss Essential
Css Essential
 
DotNetNuke World CSS3
DotNetNuke World CSS3DotNetNuke World CSS3
DotNetNuke World CSS3
 
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
 
Margin
MarginMargin
Margin
 
Compass And Sass(Tim Riley)
Compass And Sass(Tim Riley)Compass And Sass(Tim Riley)
Compass And Sass(Tim Riley)
 
Getting to Grips with Firebug
Getting to Grips with FirebugGetting to Grips with Firebug
Getting to Grips with Firebug
 
Having fun power apps components HandsOn - Power Platform World Tour Copenhag...
Having fun power apps components HandsOn - Power Platform World Tour Copenhag...Having fun power apps components HandsOn - Power Platform World Tour Copenhag...
Having fun power apps components HandsOn - Power Platform World Tour Copenhag...
 
Css (1)
Css (1)Css (1)
Css (1)
 
Oocss & progressive css3 selectors
Oocss & progressive css3 selectorsOocss & progressive css3 selectors
Oocss & progressive css3 selectors
 
CSS Basics
CSS BasicsCSS Basics
CSS Basics
 

Kürzlich hochgeladen

Design Inspiration for College by Slidesgo.pptx
Design Inspiration for College by Slidesgo.pptxDesign Inspiration for College by Slidesgo.pptx
Design Inspiration for College by Slidesgo.pptx
TusharBahuguna2
 
Brookefield Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Brookefield Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Brookefield Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Brookefield Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
amitlee9823
 
The history of music videos a level presentation
The history of music videos a level presentationThe history of music videos a level presentation
The history of music videos a level presentation
amedia6
 
Recommendable # 971589162217 # philippine Young Call Girls in Dubai By Marina...
Recommendable # 971589162217 # philippine Young Call Girls in Dubai By Marina...Recommendable # 971589162217 # philippine Young Call Girls in Dubai By Marina...
Recommendable # 971589162217 # philippine Young Call Girls in Dubai By Marina...
home
 
call girls in Dakshinpuri (DELHI) 🔝 >༒9953056974 🔝 genuine Escort Service 🔝✔️✔️
call girls in Dakshinpuri  (DELHI) 🔝 >༒9953056974 🔝 genuine Escort Service 🔝✔️✔️call girls in Dakshinpuri  (DELHI) 🔝 >༒9953056974 🔝 genuine Escort Service 🔝✔️✔️
call girls in Dakshinpuri (DELHI) 🔝 >༒9953056974 🔝 genuine Escort Service 🔝✔️✔️
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Government polytechnic college-1.pptxabcd
Government polytechnic college-1.pptxabcdGovernment polytechnic college-1.pptxabcd
Government polytechnic college-1.pptxabcd
shivubhavv
 
B. Smith. (Architectural Portfolio.).pdf
B. Smith. (Architectural Portfolio.).pdfB. Smith. (Architectural Portfolio.).pdf
B. Smith. (Architectural Portfolio.).pdf
University of Wisconsin-Milwaukee
 
Peaches App development presentation deck
Peaches App development presentation deckPeaches App development presentation deck
Peaches App development presentation deck
tbatkhuu1
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 
CALL ON ➥8923113531 🔝Call Girls Kalyanpur Lucknow best Female service 🧵
CALL ON ➥8923113531 🔝Call Girls Kalyanpur Lucknow best Female service  🧵CALL ON ➥8923113531 🔝Call Girls Kalyanpur Lucknow best Female service  🧵
CALL ON ➥8923113531 🔝Call Girls Kalyanpur Lucknow best Female service 🧵
anilsa9823
 

Kürzlich hochgeladen (20)

Design Inspiration for College by Slidesgo.pptx
Design Inspiration for College by Slidesgo.pptxDesign Inspiration for College by Slidesgo.pptx
Design Inspiration for College by Slidesgo.pptx
 
Brookefield Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Brookefield Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Brookefield Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Brookefield Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
 
The history of music videos a level presentation
The history of music videos a level presentationThe history of music videos a level presentation
The history of music videos a level presentation
 
Recommendable # 971589162217 # philippine Young Call Girls in Dubai By Marina...
Recommendable # 971589162217 # philippine Young Call Girls in Dubai By Marina...Recommendable # 971589162217 # philippine Young Call Girls in Dubai By Marina...
Recommendable # 971589162217 # philippine Young Call Girls in Dubai By Marina...
 
call girls in Dakshinpuri (DELHI) 🔝 >༒9953056974 🔝 genuine Escort Service 🔝✔️✔️
call girls in Dakshinpuri  (DELHI) 🔝 >༒9953056974 🔝 genuine Escort Service 🔝✔️✔️call girls in Dakshinpuri  (DELHI) 🔝 >༒9953056974 🔝 genuine Escort Service 🔝✔️✔️
call girls in Dakshinpuri (DELHI) 🔝 >༒9953056974 🔝 genuine Escort Service 🔝✔️✔️
 
Government polytechnic college-1.pptxabcd
Government polytechnic college-1.pptxabcdGovernment polytechnic college-1.pptxabcd
Government polytechnic college-1.pptxabcd
 
B. Smith. (Architectural Portfolio.).pdf
B. Smith. (Architectural Portfolio.).pdfB. Smith. (Architectural Portfolio.).pdf
B. Smith. (Architectural Portfolio.).pdf
 
Best VIP Call Girls Noida Sector 44 Call Me: 8448380779
Best VIP Call Girls Noida Sector 44 Call Me: 8448380779Best VIP Call Girls Noida Sector 44 Call Me: 8448380779
Best VIP Call Girls Noida Sector 44 Call Me: 8448380779
 
Booking open Available Pune Call Girls Kirkatwadi 6297143586 Call Hot Indian...
Booking open Available Pune Call Girls Kirkatwadi  6297143586 Call Hot Indian...Booking open Available Pune Call Girls Kirkatwadi  6297143586 Call Hot Indian...
Booking open Available Pune Call Girls Kirkatwadi 6297143586 Call Hot Indian...
 
SD_The MATATAG Curriculum Training Design.pptx
SD_The MATATAG Curriculum Training Design.pptxSD_The MATATAG Curriculum Training Design.pptx
SD_The MATATAG Curriculum Training Design.pptx
 
AMBER GRAIN EMBROIDERY | Growing folklore elements | Root-based materials, w...
AMBER GRAIN EMBROIDERY | Growing folklore elements |  Root-based materials, w...AMBER GRAIN EMBROIDERY | Growing folklore elements |  Root-based materials, w...
AMBER GRAIN EMBROIDERY | Growing folklore elements | Root-based materials, w...
 
💫✅jodhpur 24×7 BEST GENUINE PERSON LOW PRICE CALL GIRL SERVICE FULL SATISFACT...
💫✅jodhpur 24×7 BEST GENUINE PERSON LOW PRICE CALL GIRL SERVICE FULL SATISFACT...💫✅jodhpur 24×7 BEST GENUINE PERSON LOW PRICE CALL GIRL SERVICE FULL SATISFACT...
💫✅jodhpur 24×7 BEST GENUINE PERSON LOW PRICE CALL GIRL SERVICE FULL SATISFACT...
 
Pastel Portfolio _ by Slidesgo.pptx. Xxx
Pastel Portfolio _ by Slidesgo.pptx. XxxPastel Portfolio _ by Slidesgo.pptx. Xxx
Pastel Portfolio _ by Slidesgo.pptx. Xxx
 
Peaches App development presentation deck
Peaches App development presentation deckPeaches App development presentation deck
Peaches App development presentation deck
 
(AISHA) Ambegaon Khurd Call Girls Just Call 7001035870 [ Cash on Delivery ] P...
(AISHA) Ambegaon Khurd Call Girls Just Call 7001035870 [ Cash on Delivery ] P...(AISHA) Ambegaon Khurd Call Girls Just Call 7001035870 [ Cash on Delivery ] P...
(AISHA) Ambegaon Khurd Call Girls Just Call 7001035870 [ Cash on Delivery ] P...
 
Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Gi...
Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Gi...Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Gi...
Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Gi...
 
Booking open Available Pune Call Girls Nanded City 6297143586 Call Hot India...
Booking open Available Pune Call Girls Nanded City  6297143586 Call Hot India...Booking open Available Pune Call Girls Nanded City  6297143586 Call Hot India...
Booking open Available Pune Call Girls Nanded City 6297143586 Call Hot India...
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
Call Girls Service Mukherjee Nagar @9999965857 Delhi 🫦 No Advance VVIP 🍎 SER...
Call Girls Service Mukherjee Nagar @9999965857 Delhi 🫦 No Advance  VVIP 🍎 SER...Call Girls Service Mukherjee Nagar @9999965857 Delhi 🫦 No Advance  VVIP 🍎 SER...
Call Girls Service Mukherjee Nagar @9999965857 Delhi 🫦 No Advance VVIP 🍎 SER...
 
CALL ON ➥8923113531 🔝Call Girls Kalyanpur Lucknow best Female service 🧵
CALL ON ➥8923113531 🔝Call Girls Kalyanpur Lucknow best Female service  🧵CALL ON ➥8923113531 🔝Call Girls Kalyanpur Lucknow best Female service  🧵
CALL ON ➥8923113531 🔝Call Girls Kalyanpur Lucknow best Female service 🧵
 

CSS in all its Glory

  • 1. 1
  • 2. 2
  • 3. 3
  • 4. 4
  • 5. 5
  • 6. 6
  • 7. 6 1 + = holy crap 7
  • 8. 8
  • 9. 9
  • 10. 10
  • 11. 11
  • 12. 12
  • 13. 13
  • 14. 14
  • 15. 15
  • 16. I hope you know HTML 16
  • 17. The most important thing you need to know... 17
  • 18. 18
  • 19. The Box Model Margin 10 Border 5 Padding 10 10 5 10 200 x 80 10 5 10 10 5 10 19
  • 20. width padding-left padding-right border-left + border-right Calculated Width 20
  • 21. Width = 250px Margin 10 Border 5 Padding 10 10 5 10 200 x 80 10 5 10 10 5 10 21
  • 22. height padding-top padding-bottom border-top + border-bottom Calculated Height 22
  • 23. Height = 130px Margin 10 Border 5 Padding 10 10 5 10 200 x 80 10 5 10 10 5 10 23
  • 24. Block Level Elements Parent Element width:auto If no width declared all block level elements within the parent element will be set to 100%. 24
  • 25. Block Level Elements Parent Element width:200px If you declare a width...well your block level element will have that width, regardless of the parent element 25
  • 26. Absolute Elements Parent Element well hello there well hello there...the box expands If you don’t specify a width, the box will expand with the content. It will expand until 100% of the parent, then wrap. 26
  • 27. Floated Elements Parent Element well hello there well hello there...the box expands Mimics the behavior of positioned elements. Doesn’t depend on relative positioning 27
  • 28. Rule of Thumb Specify the width on: • floated elements • positioned elements either fixed or absolute 28
  • 29. Inline Elements Parent Element well hello there well hello there...the box expands well hello there well hello there...the box expands Just really long, skinny boxes 29
  • 31. CSS Rule Set Tells a browser how to render HTML boxes Selector Declaration Block Declaration Declaration Property Value Property Value body { color :black ; padding:1em ; } 31
  • 32. CSS Rule Set Tells a browser how to render HTML elements Selector Declaration Block Declaration Declaration Property Value Property Value body { color :black ; padding:1em ; } 32
  • 33. Selector Declaration Block Declaration Declaration Property Value Property Value body { color :black ; padding:1em ; } Selector: “selects” an HTML element that should be affected by a rule set 33
  • 34. Selector Declaration Block Declaration Declaration Property Value Property Value body { color :black ; padding:1em ; } Declaration Block: anything between the curly brackets 34
  • 35. Selector Declaration Block Declaration Declaration Property Value Property Value body { color :black ; padding:1em ; } Declaration: Tells the browser how to draw any element on a page that is selected 35
  • 36. Selector Declaration Block Declaration Declaration Property Value Property Value body { color :black ; padding:1em ; } Property: The aspects of the HTML element that you are choosing to style. 36
  • 37. Selector Declaration Block Declaration Declaration Property Value Property Value body { color :black ; padding:1em ; } Value: The exact style you want to set for the property 37
  • 38. All together now Declarations can be grouped. p{ margin: 10px; padding: 20px; } 38
  • 39. All together now Selectors can be grouped. h1, h2, h3 { padding:10px; } 39
  • 41. Font h1{ font-family: Arial; font-size: 100%; font-style: normal; font-variant: small-caps; font-weight: bold; line-height:120%; } 41
  • 42. Font h1{ font: bold small-caps 100%/120% Arial; } 42
  • 43. Font style variant size line-height font-family font: bold small-caps 100% 120% Arial ; 43
  • 44. Margin/Padding p{ margin-top: 1px; margin-right: 2px; margin-bottom: 3px; margin-left: 4px; padding-top: 1px; padding-right: 2px; padding-bottom: 3px; padding-left: 4px; } 44
  • 45. Margin/Padding T L R B margin: 1px 2px 3px 4px; padding: 1px 2px 3px 4px; 45
  • 46. Margin/Padding T R B L margin: 1px 2px 3px 4px; padding: 1px 2px 3px 4px; 46
  • 47. Margin/Padding T R/L B margin: 1px 2px 3px 2px; padding: 1px 2px 3px 2px; T/B R/L margin: 1px 2px 1px 2px; padding: 1px 2px 1px 2px; 47
  • 48. Margin/Padding T/R/B/L margin: 1px 1px 1px 1px; padding: 1px 1px 1px 1px; 48
  • 49. Comments /* Comment */ margin: 1px 2px 3px 4px; /*padding: 1px 2px 3px 4px;*/ 49
  • 51. <body> <div id="container"> <h1>This is the document tree</h1> <p>Lorem ipsum dolor sit amet.</p> <p>Lorem ipsum <strong>dolor</strong> sit amet</p> </div> <div id="nav"> <ul> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li> </ul> </div> </body> 51
  • 52. body div div h1 p p ul em li li li 52
  • 53. body div div h1 p p ul em li li li Ancestor Any element that’s connected but further up the document tree, no matter how many level higher. 53
  • 54. body div div h1 p p ul em li li li Descendant Any element that’s connected but lower down the document tree, no matter how many levels lower. 54
  • 55. body div div Parent h1 p p ul Child em li li li Parent Element that is directly above and connected to an element in the document tree 55
  • 56. body div div Parent h1 p p ul Child em li li li Child Element that is directly below and connected to an element in the document tree 56
  • 57. body div div h1 p p ul em li li li Siblings An element that shares the same parent with another element 57
  • 58. Specificity Determines which CSS rule is applied to an element by a browser 58
  • 59. Basic Specificity Inline Style > #ID > .Class > Element 59
  • 60. Selectors 60
  • 61. Type Selectors li{color: red;} body div div h1 p p ul em li li li 61
  • 62. Class Selectors .red{color: red;} body div div h1 p p.red ul em li li li.red 62
  • 63. Class + Type Selectors p.red{color: red;} body div div h1 p p.red ul em li li li.red 63
  • 64. Rule of Thumb Don’t use classes to style HTML elements to look like other elements <div class="heading">Main Heading</div> .heading{ font-weight: bold; font-size: 140%; } 64
  • 65. Rule of Thumb Do HTML elements that already exist <h1>Main Heading</h1> h1{ font-size: 140%; } 65
  • 66. Think before you class 1. Is there an existing HTML element that I can use instead? 2. Is there a class or ID further up the document tree that can be used? 66
  • 67. ID Selectors #nav{color: red;} body div div h1 p p.red ul nav # em li li li.red 67
  • 68. ID vs .class ID’s • They are unique • Each element can only have one ID • Each page can only have one element with the same ID • ID’s have special browser functionality • Javascript loves ID’s <div id="nav header"></div> 68
  • 69. ID vs .class Classes • They aren’t unique • The same class can be used on multiple elements • You can use multiple classes on the same element <div class="nav header"></div> 69
  • 70. Descendant Selectors p em{color: red;} body div div h1 p p.red ul nav # em li li li.red 70
  • 71. Universal Selectors * {color: red;} body div div h1 p p.red ul nav # em li li li.red 71
  • 72. Child Selectors div > em {color: red;} body div div h1 p p.red ul nav em # em li li li.red 72
  • 73. Adjacent Sibling Selectors h1 + p {color: red;} body div div h1 p p.red ul nav em # em li li li.red 73
  • 74. Attribute Selectors 4 Types 74
  • 75. Attribute Selectors Select based on the attribute <img src="image.png" width="100" height="100" title="Main Image" alt="Main Image"/> img[title] { border: 1px solid #000; } img[width] { border: 1px solid #000; } img[alt] { border: 1px solid #000; } 75
  • 76. Attribute Selectors Select based on the attribute’s value <img src="image.png" width="100" height="100" title="Main Image" alt="Main Image"/> img[src="image.png"] { border: 1px solid #000; } 76
  • 77. Attribute Selectors Select based on the space separated instances of a value <img src="image.png" width="100" height="100" title="Main Image" alt="Main Image"/> img[alt~="Main"] { border: 1px solid #000; } 77
  • 78. Attribute Selectors Select based on the hyphen separated instances of a value <img src="image.png" width="100" height="100" title="Main Image" alt="Main Image"/> img[alt|="Main"] { border: 1px solid #000; } 78
  • 80. Most Common :link :visited :hover :active 80
  • 81. :first-child li:first-child {color: red;} body div div h1 p p.red ul nav em # em li li li.red 81
  • 82. :first-line p:first-line {color: red;} Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum rutrum purus non risus porttitor convallis. In vitae nulla id felis. 82
  • 83. :before and :after p:before {content: “ extra stuff”} Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum rutrum purus non risus porttitor convallis. In vitae nulla id felis. extra stuff 83
  • 85. Most Common :link :visited :hover :active 85
  • 86. :first-child li:first-child {color: red;} body div div h1 p p.red ul nav em # em li li li.red 86
  • 87. :first-line p:first-line {color: red;} Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum rutrum purus non risus porttitor convallis. In vitae nulla id felis. 87
  • 88. :before and :after p:before {content: “ extra stuff”} Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum rutrum purus non risus porttitor convallis. In vitae nulla id felis. extra stuff 88
  • 89. CSS 3 I shall now cheat...I’m also lazy http://www.css3.info/ 89
  • 91. • Absolute Positioning (z-index) • Multi-Column Layouts with floats • .clearfix • Image Sprites • Image Replacement • Center align elements • display:none vs visibility:hidden • Multiple background images 91
  • 94. Books Designing with Transcending CSS CSS Mastery Web Standards Andy Clarke Andy Budd Jeffry Zeldman 94