SlideShare a Scribd company logo
1 of 52
CSS Overview
                               Cascading Style Sheets


Svetlin Nakov
Manager Technical Training
http://nakov.com
Telerik Web Design Course
html5course.telerik.com
Table of Contents
    What is CSS?
    Styling with Cascading Stylesheets (CSS)
    Selectors and style definitions
    Linking HTML and CSS
    Font and text styles
    Backgrounds
     Colors and images

                                                2
CSS: A New Philosophy
 Separate content from presentation!



         Content                                       Presentation
     (HTML document)                                 (CSS Document)

       Title
       Lorem ipsum dolor sit amet,
                                                       Bold
       consectetuer adipiscing elit.
       Suspendisse at pede ut purus                    Italics
       malesuada dictum. Donec vitae
       neque non magna aliquam
       dictum.                                         Indent
       • Vestibulum et odio et ipsum
       • accumsan accumsan. Morbi at
       • arcu vel elit ultricies porta. Proin
       tortor purus, luctus non, aliquam
       nec, interdum vel, mi. Sed nec
       quam nec odio lacinia molestie.
       Praesent augue tortor, convallis
       eget, euismod nonummy, lacinia
       ut, risus.




                                                                        3
The Resulting Page
Title
Lorem ipsum dolor sit amet,
consectetuer adipiscing elit.
Suspendisse at pede ut purus
malesuada dictum. Donec vitae neque
non magna aliquam dictum.
    • Vestibulum et odio et ipsum
    • accumsan accumsan. Morbi at
    • arcu vel elit ultricies porta. Proin
Tortor purus, luctus non, aliquam nec,
interdum vel, mi. Sed nec quam nec
odio lacinia molestie. Praesent augue
tortor, convallis eget, euismod
nonummy, lacinia ut, risus.

                                             4
CSS Intro
Styling with Cascading Stylesheets
CSS Introduction
   Cascading Style Sheets (CSS)
     Used to describe the presentation of documents
     Define sizes, spacing, fonts, colors, layout, etc.
     Improve content accessibility
     Improve flexibility
   Designed to separate presentation from content
   Due to CSS, all HTML presentation tags and
    attributes are deprecated, e.g. font, center, etc.


                                                           6
CSS Introduction (2)
 CSS can be applied to any XML document

   Not just to HTML / XHTML
 CSS can specify different styles for different

 media
   On-screen
   In print
   Handheld, projection, etc.
   … even by voice or Braille-based reader

                                                   7
Why “Cascading”?
 Priority scheme determining which style rules

 apply to element
   Cascade priorities or specificity (weight) are
    calculated and assigned to the rules
   Child elements in the HTML DOM tree inherit
    styles from their parent
    Can override them
    Control via !important rule


                                                     8
Why “Cascading”? (2)




                       9
Stile Inheritance
 Some CSS styles are inherited and some not

  Text-related and list-related properties are
   inherited - color, font-size, font-family,
   line-height, text-align, list-style, etc.
  Box-related and positioning styles are not
   inherited - width, height, border, margin,
   padding, position, float, etc
  <a> elements do not inherit color and text-
   decoration

                                                  10
Style Sheets Syntax
   Stylesheets consist of rules, selectors,
    declarations, properties and values




                http://css.maxdesign.com.au/
   Selectors are separated by commas
   Declarations are separated by semicolons
   Properties and values are separated by colons
     h1,h2,h3 { color: green; font-weight: bold; }
                                                     11
Selectors
 Selectors determine which element the rule

 applies to:
  All elements of specific type (tag)
  Those that match a specific attribute (id, class)
  Elements may be matched depending on how
   they are nested in the document tree (HTML)
 Examples:

  .header a { color: green }

  #menu>li { padding-top: 8px }
                                                       12
Selectors (2)
   Three primary kinds of selectors:
     By tag (type selector):
     h1 { font-family: verdana,sans-serif; }
     By element id:
     #element_id { color: #ff0000; }
     By element class name (only for HTML):
     .myClass {border: 1px solid red}
   Selectors can be combined with commas:
     h1, .link, #top-link {font-weight: bold}

    This will match <h1> tags, elements with class
    link, and the element with id top-link
                                                     13
Selectors (3)
 Pseudo-classes define state

   :hover, :visited, :active , :lang
 Pseudo-elements define element "parts" or are

 used to generate content
   :first-line , :before, :after

  a:hover { color: red; }
  p:first-line { text-transform: uppercase; }
  .title:before { content: "»"; }
  .title:after { content: "«"; }


                                                  14
Selectors (4)
   Match relative to element placement:
     p a {text-decoration: underline}

    This will match all <a> tags that are inside of <p>
   * – universal selector (avoid or use with care!):
     p * {color: black}

    This will match all descendants of <p> element
   + selector – used to match “next sibling”:
     img + .link {float:right}

    This will match all siblings with class name link
    that appear immediately after <img> tag               15
Selectors (5)
   > selector – matches direct child nodes:
      p > .error {font-size: 8px}
  This will match all elements with class error, direct
  children of <p> tag
 [ ] – matches tag attributes by regular expression:


      img[alt~=logo] {border: none}
    This will match all <img> tags with alt attribute
    containing the word logo
   .class1.class2 (no space) - matches elements
    with both (all) classes applied at the same time

                                                          16
Values in the CSS Rules
   Colors are set in RGB format (decimal or hex):
     Example: #a0a6aa = rgb(160, 166, 170)
     Predefined color aliases exist: black, blue, etc.
   Numeric values are specified in:
     Pixels, ems, e.g. 12px , 1.4em
     Points, inches, centimeters, millimeters
       E.g. 10pt , 1in, 1cm, 1mm
     Percentages, e.g. 50%
       Percentage of what?...
     Zero can be used with no unit: border: 0;
                                                          17
Default Browser Styles
 Browsers have predefined CSS styles

   Used when there is no CSS information or any
    other style information in the document
 Caution: default styles differ in browsers

   E.g. margins, paddings and font sizes differ
    most often
   Usually developers reset them
    * { margin: 0; padding: 0; }

    body, h1, p, ul, li { margin: 0; padding: 0; }

                                                     18
Linking HTML and CSS
 HTML (content) and CSS (presentation) can be
 linked in three ways:
  Inline: the CSS rules in the style attribute
    No selectors are needed
  Embedded: in the <head> in a <style> tag
  External: CSS rules in separate file (best)
    Usually a file with .css extension
    Linked via <link rel="stylesheet" href="
     …"> tag
    Via @import directive in embedded CSS block
                                                   19
Linking HTML and CSS (2)

 Using external files is highly recommended

   Simplifies the HTML document
   Improves page load speed as the CSS file is
    cached




                                                  20
Inline Styles: Example
inline-styles.html
<!DOCTYPE html>
<html lang="en">
<head>
  <title>Inline Styles</title>
</head>
<body>
  <p>Here is some text</p>
<!--Separate multiple styles with a semicolon-->
  <p style="font-size: 20pt">Here is some
    more text</p>
  <p style="font-size: 20pt;color:
    #0000FF" >Even more text</p>
</body>
</html>



                                                   21
Inline Styles: Example
inline-styles.html
<!DOCTYPE html>
<html lang="en">
<head>
  <title>Inline Styles</title>
</head>
<body>
  <p>Here is some text</p>
<!--Separate multiple styles with a semicolon-->
  <p style="font-size: 20pt">Here is some
    more text</p>
  <p style="font-size: 20pt;color:
    #0000FF" >Even more text</p>
</body>
</html>



                                                   22
CSS Cascade (Precedence)
 There are browser, user and author stylesheets

 with "normal" and "important" declarations
   Browser styles (least priority)
   Normal user styles
   Normal author styles (external, in head, inline)
   Important author styles
   Important user styles (max priority)
    a { color: red !important ; }

  http://www.slideshare.net/maxdesign/css-cascade-1658158
                                                            23
CSS Specificity
 CSS specificity is used to determine the

 precedence of CSS style declarations with the
 same origin. Selectors are what matters
   Simple calculation: #id = 100, .class = 10,
    :pseudo = 10, [attr] = 10, tag = 1, * = 0
   Same number of points? Order matters!
   See also:
   http://www.smashingmagazine.com/2007/07/27/css-specificity-things-you-


   http://css.maxdesign.com.au/selectutorial/advanced_conflict.htm

                                                                       24
CSS Rules Precedence
        Live Demo
     precedence.html
Embedded Styles
 Embedded in the HTML in the <style> tag:
   <style type="text/css">

   The <style> tag is placed in the <head>
    section of the document
   type attribute specifies the MIME type
    MIME describes the format of the content
    Other MIME types include text/html,
     image/gif, text/javascript …
 Used for document-specific styles


                                                26
Embedded Styles: Example

embedded-stylesheets.html
<!DOCTYPE html>
<html>
<head>
  <title>Style Sheets</title>
  <style type="text/css">
    em {background-color:#8000FF; color:white}
    h1 {font-family:Arial, sans-serif}
    p {font-size:18pt}
    .blue {color:blue}
  </style>
<head>



                                                 27
Embedded Styles: Example (2)
…
<body>
  <header>
       <h1 class="blue">A Heading</h1>
  </header>
  <article>
       <p>Here is some text. Here is some text.
       Here is some text. Here is some text. Here
       is some text.</p>
     <h1>Another Heading</h1>
     <p class="blue">Here is some more text.
     Here is some more text.</p>
     <p class="blue">Here is some <em>more</em>
     text. Here is some more text.</p>
  </article>
</body>
</html>
                                                    28
Embedded Styles: Example (3)
…
<body>
  <header>
       <h1 class="blue">A Heading</h1>
  </header>
  <article>
       <p>Here is some text. Here is some text.
       Here is some text. Here is some text. Here
       is some text.</p>
     <h1>Another Heading</h1>
     <p class="blue">Here is some more text.
     Here is some more text.</p>
     <p class="blue">Here is some <em>more</em>
     text. Here is some more text.</p>
  </article>
</body>
</html>
                                                    29
External CSS Styles
   External linking
     Separate pages can all use a shared style sheet
     Only modify a single file to change the styles across
      your entire Web site (see http://www.csszengarden.com/)
   link tag (with a rel attribute)
     Specifies a relationship between current document
      and another document
      <link rel="stylesheet" type="text/css"
        href="styles.css">
     link elements should be in the <head>
                                                                30
External CSS Styles (2)
@import
  Another way to link external CSS files
  Example:
  <style type="text/css">
    @import url("styles.css");
    /* same as */
    @import "styles.css";
  </style>

  Ancient browsers do not recognize @import

  Use @import in an external CSS file to
   workaround the IE 32 CSS file limit
                                               31
External Styles: Example
styles.css
/* CSS Document */

a       { text-decoration: none }

a:hover { text-decoration: underline;
          color: red;
          background-color: #CCFFCC }

li em   { color: red;
          font-weight: bold }

ul      { margin-left: 2cm }

ul ul   { text-decoration: underline;
          margin-left: .5cm }

                                        32
External Styles: Example (2)
external-styles.html
<!DOCTYPE html>
<html>
<head>
  <title>Importing style sheets</title>
  <link type="text/css" rel="stylesheet"
    href="styles.css" />
</head>
<body>
  <h1>Shopping list for <em>Monday</em>:</h1>
  <li>Milk</li>
  …




                                                33
External Styles: Example (3)
  …
  <li>Bread
    <ul>
      <li>White bread</li>
      <li>Rye bread</li>
      <li>Whole wheat bread</li>
    </ul>
  </li>
  <li>Rice</li>
  <li>Potatoes</li>
  <li>Pizza <em>with mushrooms</em></li>
</ul>
<a href="http://food.com" title="grocery
  store">Go to the Grocery store</a>
</body>
</html>
                                           34
External Styles: Example (4)
  …
  <li>Bread
    <ul>
      <li>White bread</li>
      <li>Rye bread</li>
      <li>Whole wheat bread</li>
    </ul>
  </li>
  <li>Rice</li>
  <li>Potatoes</li>
  <li>Pizza <em>with mushrooms</em></li>
</ul>
<a href="http://food.com" title="grocery
  store">Go to the Grocery store</a>
</body>
</html>
                                           35
Text Related Properties
Text-related CSS Properties
   color – specifies the color of the text
   font-size – size of font: xx-small, x-small,
    small, medium, large, x-large, xx-large,
    smaller, larger or numeric value
   font-family – comma separated font names
     Example: verdana, sans-serif, etc.
     The browser loads the first one that is available
     There should always be at least one generic font
   font-weight can be normal, bold, bolder,
    lighter or a number in range [100 … 900]
                                                          37
CSS Rules for Fonts (2)
 font-style – styles the font

  Values: normal, italic, oblique
 text-decoration – decorates the text

  Values: none, underline, line-trough,
   overline, blink
 text-align – defines the alignment of text or

 other content
  Values: left, right, center, justify


                                                  38
Shorthand Font Property
 font

  Shorthand rule for setting multiple font
   properties at the same time
   font:italic normal bold 12px/16px verdana
   is equal to writing this:
   font-style: italic;
   font-variant: normal;
   font-weight: bold;
   font-size: 12px;
   line-height: 16px;
   font-family: verdana;
                                               39
Fonts
  Live Demo
font-rules.html
Background Properties
Backgrounds
 background-image

  URL of image to be used as background, e.g.:
   background-image:url("back.gif");

 background-color

  Using color and image and the same time
 background-repeat

  repeat-x, repeat-y, repeat, no-repeat
 background-attachment

  fixed / scroll                                 42
Backgrounds (2)
 background-position: specifies vertical and

 horizontal position of the background image
  Vertical position: top, center, bottom
  Horizontal position: left, center, right
  Both can be specified in percentage or other
   numerical values
  Examples:
    background-position: top left;

    background-position: -5px 50%;
                                                  43
Background Shorthand Property
   background: shorthand rule for setting
    background properties at the same time:
    background: #FFF0C0 url("back.gif") no-repeat
    fixed top;


    is equal to writing:
    background-color: #FFF0C0;
    background-image: url("back.gif");
    background-repeat: no-repeat;
    background-attachment: fixed;
    background-position: top;


     Some browsers will not apply BOTH color and
      image for background if using shorthand rule   44
Background-image or <img>?
 Background images allow you to save many

 image tags from the HTML
   Leads to less code
   More content-oriented approach
 All images that are not part of the page

 content (and are used only for "beautification")
 should be moved to the CSS



                                                    45
Background Styles
      Live Demo
 background-rules.html
CSS Reference
 A list of all CSS 2.1 properties is available at

 http://www.w3.org/TR/CSS2/propidx.html




                                                     47
CSS Overview




http://html5course.telerik.com
Homework
1.   Create the following page section using HTML and
     external CSS (no inline styles). Use a table or a
     definition list (in this case the layout will be
     different).




                                                         49
Homework (2)
1.   Create the following Web page using external CSS
     styles.




                                                        50
Homework (3)
1.   Implement the following
     using CSS styles




                                          51
Homework (4)
1.   Implement the following using tables and CSS




                                                    52

More Related Content

What's hot

Intro to HTML and CSS basics
Intro to HTML and CSS basicsIntro to HTML and CSS basics
Intro to HTML and CSS basicsEliran Eliassy
 
Complete Lecture on Css presentation
Complete Lecture on Css presentation Complete Lecture on Css presentation
Complete Lecture on Css presentation Salman Memon
 
Introduction to HTML
Introduction to HTMLIntroduction to HTML
Introduction to HTMLAmit Tyagi
 
Web front end development introduction to html css and javascript
Web front end development introduction to html css and javascriptWeb front end development introduction to html css and javascript
Web front end development introduction to html css and javascriptMarc Huang
 
FFW Gabrovo PMG - HTML
FFW Gabrovo PMG - HTMLFFW Gabrovo PMG - HTML
FFW Gabrovo PMG - HTMLToni Kolev
 
Intro webtechstc
Intro webtechstcIntro webtechstc
Intro webtechstccmcsubho
 
Cascading Style Sheets - CSS
Cascading Style Sheets - CSSCascading Style Sheets - CSS
Cascading Style Sheets - CSSSun Technlogies
 
CSS Foundations, pt 1
CSS Foundations, pt 1CSS Foundations, pt 1
CSS Foundations, pt 1Shawn Calvert
 

What's hot (20)

HTML CSS Basics
HTML CSS BasicsHTML CSS Basics
HTML CSS Basics
 
HTML & XHTML Basics
HTML & XHTML BasicsHTML & XHTML Basics
HTML & XHTML Basics
 
Web Typography
Web TypographyWeb Typography
Web Typography
 
Images on the Web
Images on the WebImages on the Web
Images on the Web
 
Intro to HTML and CSS basics
Intro to HTML and CSS basicsIntro to HTML and CSS basics
Intro to HTML and CSS basics
 
Week 2-intro-html
Week 2-intro-htmlWeek 2-intro-html
Week 2-intro-html
 
Complete Lecture on Css presentation
Complete Lecture on Css presentation Complete Lecture on Css presentation
Complete Lecture on Css presentation
 
Introduction to HTML
Introduction to HTMLIntroduction to HTML
Introduction to HTML
 
Basic css
Basic cssBasic css
Basic css
 
Web front end development introduction to html css and javascript
Web front end development introduction to html css and javascriptWeb front end development introduction to html css and javascript
Web front end development introduction to html css and javascript
 
FFW Gabrovo PMG - HTML
FFW Gabrovo PMG - HTMLFFW Gabrovo PMG - HTML
FFW Gabrovo PMG - HTML
 
Basic-CSS-tutorial
Basic-CSS-tutorialBasic-CSS-tutorial
Basic-CSS-tutorial
 
CSS ppt
CSS pptCSS ppt
CSS ppt
 
Intro webtechstc
Intro webtechstcIntro webtechstc
Intro webtechstc
 
Cascading Style Sheets - CSS
Cascading Style Sheets - CSSCascading Style Sheets - CSS
Cascading Style Sheets - CSS
 
Css
CssCss
Css
 
Full
FullFull
Full
 
CSS Foundations, pt 1
CSS Foundations, pt 1CSS Foundations, pt 1
CSS Foundations, pt 1
 
CSS Part I
CSS Part ICSS Part I
CSS Part I
 
Html and css
Html and cssHtml and css
Html and css
 

Viewers also liked

How To Dress: Like Steve McQueen
How To Dress: Like Steve McQueenHow To Dress: Like Steve McQueen
How To Dress: Like Steve McQueenSam Brady
 
OEG tools for supporting Ontology Engineering
OEG tools for supporting Ontology EngineeringOEG tools for supporting Ontology Engineering
OEG tools for supporting Ontology Engineeringdgarijo
 
Digital Daybreak Talk
Digital Daybreak TalkDigital Daybreak Talk
Digital Daybreak TalkSam Brady
 
Create update checklist items
Create update checklist itemsCreate update checklist items
Create update checklist itemsmrsccarle3
 
Qué es el lavado de dinero
Qué es el lavado de dineroQué es el lavado de dinero
Qué es el lavado de dineroToño Bcrra
 
Testes para aplicativos movéis
Testes para aplicativos movéisTestes para aplicativos movéis
Testes para aplicativos movéisLeandro Rodrigues
 
Самые дорогие и НЕ самые дорогие проекты Kaizen Blitz
Самые дорогие и НЕ самые дорогие проекты Kaizen BlitzСамые дорогие и НЕ самые дорогие проекты Kaizen Blitz
Самые дорогие и НЕ самые дорогие проекты Kaizen BlitzSixSigmaOnline
 
Plantas de tratamiento aclara periódico corporativo Mayo 2016
Plantas de tratamiento aclara periódico corporativo Mayo 2016Plantas de tratamiento aclara periódico corporativo Mayo 2016
Plantas de tratamiento aclara periódico corporativo Mayo 2016AclaraPTARs
 
Overcoming Complexities in Stakeholder Management
Overcoming Complexities in Stakeholder ManagementOvercoming Complexities in Stakeholder Management
Overcoming Complexities in Stakeholder ManagementBilikisu Wunmi Aderinto
 
Plantas de tratamiento aclara periódico corporativo marzo 2016
Plantas de tratamiento aclara periódico corporativo marzo 2016Plantas de tratamiento aclara periódico corporativo marzo 2016
Plantas de tratamiento aclara periódico corporativo marzo 2016AclaraPTARs
 
Повышение количества заказов, сданных в срок на участке трафаретной печати
Повышение количества заказов, сданных в срок на участке трафаретной печатиПовышение количества заказов, сданных в срок на участке трафаретной печати
Повышение количества заказов, сданных в срок на участке трафаретной печатиSixSigmaOnline
 
Cнижение брака по параметру INC
Cнижение брака по параметру INCCнижение брака по параметру INC
Cнижение брака по параметру INCSixSigmaOnline
 
Обеспечение безотказности эксплуатации думпкара 2вс 105 по буксовому узлу
Обеспечение  безотказности эксплуатации думпкара 2вс 105 по буксовому узлуОбеспечение  безотказности эксплуатации думпкара 2вс 105 по буксовому узлу
Обеспечение безотказности эксплуатации думпкара 2вс 105 по буксовому узлуSixSigmaOnline
 
Aviation PPT Frankfinn
Aviation PPT FrankfinnAviation PPT Frankfinn
Aviation PPT FrankfinnHarsh Soni
 
Relationship building
Relationship building Relationship building
Relationship building Nimi jayan
 

Viewers also liked (20)

CSS3
CSS3CSS3
CSS3
 
MyReferences
MyReferencesMyReferences
MyReferences
 
How To Dress: Like Steve McQueen
How To Dress: Like Steve McQueenHow To Dress: Like Steve McQueen
How To Dress: Like Steve McQueen
 
OEG tools for supporting Ontology Engineering
OEG tools for supporting Ontology EngineeringOEG tools for supporting Ontology Engineering
OEG tools for supporting Ontology Engineering
 
Digital Daybreak Talk
Digital Daybreak TalkDigital Daybreak Talk
Digital Daybreak Talk
 
resume.PDF
resume.PDFresume.PDF
resume.PDF
 
Create update checklist items
Create update checklist itemsCreate update checklist items
Create update checklist items
 
Qué es el lavado de dinero
Qué es el lavado de dineroQué es el lavado de dinero
Qué es el lavado de dinero
 
Testes para aplicativos movéis
Testes para aplicativos movéisTestes para aplicativos movéis
Testes para aplicativos movéis
 
Самые дорогие и НЕ самые дорогие проекты Kaizen Blitz
Самые дорогие и НЕ самые дорогие проекты Kaizen BlitzСамые дорогие и НЕ самые дорогие проекты Kaizen Blitz
Самые дорогие и НЕ самые дорогие проекты Kaizen Blitz
 
Plantas de tratamiento aclara periódico corporativo Mayo 2016
Plantas de tratamiento aclara periódico corporativo Mayo 2016Plantas de tratamiento aclara periódico corporativo Mayo 2016
Plantas de tratamiento aclara periódico corporativo Mayo 2016
 
Distance function
Distance functionDistance function
Distance function
 
Trigliceridos
TrigliceridosTrigliceridos
Trigliceridos
 
Overcoming Complexities in Stakeholder Management
Overcoming Complexities in Stakeholder ManagementOvercoming Complexities in Stakeholder Management
Overcoming Complexities in Stakeholder Management
 
Plantas de tratamiento aclara periódico corporativo marzo 2016
Plantas de tratamiento aclara periódico corporativo marzo 2016Plantas de tratamiento aclara periódico corporativo marzo 2016
Plantas de tratamiento aclara periódico corporativo marzo 2016
 
Повышение количества заказов, сданных в срок на участке трафаретной печати
Повышение количества заказов, сданных в срок на участке трафаретной печатиПовышение количества заказов, сданных в срок на участке трафаретной печати
Повышение количества заказов, сданных в срок на участке трафаретной печати
 
Cнижение брака по параметру INC
Cнижение брака по параметру INCCнижение брака по параметру INC
Cнижение брака по параметру INC
 
Обеспечение безотказности эксплуатации думпкара 2вс 105 по буксовому узлу
Обеспечение  безотказности эксплуатации думпкара 2вс 105 по буксовому узлуОбеспечение  безотказности эксплуатации думпкара 2вс 105 по буксовому узлу
Обеспечение безотказности эксплуатации думпкара 2вс 105 по буксовому узлу
 
Aviation PPT Frankfinn
Aviation PPT FrankfinnAviation PPT Frankfinn
Aviation PPT Frankfinn
 
Relationship building
Relationship building Relationship building
Relationship building
 

Similar to CSS Overview

2 introduction css
2 introduction css2 introduction css
2 introduction cssJalpesh Vasa
 
Css training tutorial css3 &amp; css4 essentials
Css training tutorial css3 &amp; css4 essentialsCss training tutorial css3 &amp; css4 essentials
Css training tutorial css3 &amp; css4 essentialsQA TrainingHub
 
Beginners css tutorial for web designers
Beginners css tutorial for web designersBeginners css tutorial for web designers
Beginners css tutorial for web designersSingsys Pte Ltd
 
ch04-css-basics_final.ppt
ch04-css-basics_final.pptch04-css-basics_final.ppt
ch04-css-basics_final.pptGmachImen
 
Internet tech &amp; web prog. p4,5
Internet tech &amp; web prog.  p4,5Internet tech &amp; web prog.  p4,5
Internet tech &amp; web prog. p4,5Taymoor Nazmy
 
Css basics
Css basicsCss basics
Css basicsASIT
 
Chapter 4a cascade style sheet css
Chapter 4a cascade style sheet cssChapter 4a cascade style sheet css
Chapter 4a cascade style sheet cssTesfaye Yenealem
 
Unit 2-CSS & Bootstrap.ppt
Unit 2-CSS & Bootstrap.pptUnit 2-CSS & Bootstrap.ppt
Unit 2-CSS & Bootstrap.pptTusharTikia
 
4. Web Technology CSS Basics-1
4. Web Technology CSS Basics-14. Web Technology CSS Basics-1
4. Web Technology CSS Basics-1Jyoti Yadav
 
Web topic 15 1 basic css layout
Web topic 15 1  basic css layoutWeb topic 15 1  basic css layout
Web topic 15 1 basic css layoutCK Yang
 
Girl Develop It Cincinnati: Intro to HTML/CSS Class 2
Girl Develop It Cincinnati: Intro to HTML/CSS Class 2Girl Develop It Cincinnati: Intro to HTML/CSS Class 2
Girl Develop It Cincinnati: Intro to HTML/CSS Class 2Erin M. Kidwell
 
Webpage style with CSS
Webpage style with CSSWebpage style with CSS
Webpage style with CSSHemant Patidar
 
FFW Gabrovo PMG - CSS
FFW Gabrovo PMG - CSSFFW Gabrovo PMG - CSS
FFW Gabrovo PMG - CSSToni Kolev
 
2_css.pptx
2_css.pptx2_css.pptx
2_css.pptxVarunMM2
 

Similar to CSS Overview (20)

CSS.pptx
CSS.pptxCSS.pptx
CSS.pptx
 
2 introduction css
2 introduction css2 introduction css
2 introduction css
 
Css training tutorial css3 &amp; css4 essentials
Css training tutorial css3 &amp; css4 essentialsCss training tutorial css3 &amp; css4 essentials
Css training tutorial css3 &amp; css4 essentials
 
Beginners css tutorial for web designers
Beginners css tutorial for web designersBeginners css tutorial for web designers
Beginners css tutorial for web designers
 
Cascading Style Sheet
Cascading Style SheetCascading Style Sheet
Cascading Style Sheet
 
ch04-css-basics_final.ppt
ch04-css-basics_final.pptch04-css-basics_final.ppt
ch04-css-basics_final.ppt
 
Internet tech &amp; web prog. p4,5
Internet tech &amp; web prog.  p4,5Internet tech &amp; web prog.  p4,5
Internet tech &amp; web prog. p4,5
 
Css basics
Css basicsCss basics
Css basics
 
Chapter 4a cascade style sheet css
Chapter 4a cascade style sheet cssChapter 4a cascade style sheet css
Chapter 4a cascade style sheet css
 
Unit 2-CSS & Bootstrap.ppt
Unit 2-CSS & Bootstrap.pptUnit 2-CSS & Bootstrap.ppt
Unit 2-CSS & Bootstrap.ppt
 
4. Web Technology CSS Basics-1
4. Web Technology CSS Basics-14. Web Technology CSS Basics-1
4. Web Technology CSS Basics-1
 
Web topic 15 1 basic css layout
Web topic 15 1  basic css layoutWeb topic 15 1  basic css layout
Web topic 15 1 basic css layout
 
Girl Develop It Cincinnati: Intro to HTML/CSS Class 2
Girl Develop It Cincinnati: Intro to HTML/CSS Class 2Girl Develop It Cincinnati: Intro to HTML/CSS Class 2
Girl Develop It Cincinnati: Intro to HTML/CSS Class 2
 
Web technology Unit-II Part-C
Web technology Unit-II Part-CWeb technology Unit-II Part-C
Web technology Unit-II Part-C
 
Webpage style with CSS
Webpage style with CSSWebpage style with CSS
Webpage style with CSS
 
CSS
CSSCSS
CSS
 
FFW Gabrovo PMG - CSS
FFW Gabrovo PMG - CSSFFW Gabrovo PMG - CSS
FFW Gabrovo PMG - CSS
 
Css ms megha
Css ms meghaCss ms megha
Css ms megha
 
CSS
CSSCSS
CSS
 
2_css.pptx
2_css.pptx2_css.pptx
2_css.pptx
 

More from Doncho Minkov

More from Doncho Minkov (20)

Web Design Concepts
Web Design ConceptsWeb Design Concepts
Web Design Concepts
 
Web design Tools
Web design ToolsWeb design Tools
Web design Tools
 
HTML 5 Tables and Forms
HTML 5 Tables and FormsHTML 5 Tables and Forms
HTML 5 Tables and Forms
 
CSS Presentation
CSS PresentationCSS Presentation
CSS Presentation
 
CSS Layout
CSS LayoutCSS Layout
CSS Layout
 
CSS 3
CSS 3CSS 3
CSS 3
 
Adobe Photoshop
Adobe PhotoshopAdobe Photoshop
Adobe Photoshop
 
Slice and Dice
Slice and DiceSlice and Dice
Slice and Dice
 
Introduction to XAML and WPF
Introduction to XAML and WPFIntroduction to XAML and WPF
Introduction to XAML and WPF
 
WPF Layout Containers
WPF Layout ContainersWPF Layout Containers
WPF Layout Containers
 
WPF Controls
WPF ControlsWPF Controls
WPF Controls
 
WPF Templating and Styling
WPF Templating and StylingWPF Templating and Styling
WPF Templating and Styling
 
WPF Graphics and Animations
WPF Graphics and AnimationsWPF Graphics and Animations
WPF Graphics and Animations
 
Simple Data Binding
Simple Data BindingSimple Data Binding
Simple Data Binding
 
Complex Data Binding
Complex Data BindingComplex Data Binding
Complex Data Binding
 
WPF Concepts
WPF ConceptsWPF Concepts
WPF Concepts
 
Model View ViewModel
Model View ViewModelModel View ViewModel
Model View ViewModel
 
WPF and Databases
WPF and DatabasesWPF and Databases
WPF and Databases
 
Introduction to Cross-platform Mobile Development Course
Introduction to Cross-platform Mobile Development CourseIntroduction to Cross-platform Mobile Development Course
Introduction to Cross-platform Mobile Development Course
 
HTML Fundamentals
HTML FundamentalsHTML Fundamentals
HTML Fundamentals
 

Recently uploaded

My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 

Recently uploaded (20)

My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 

CSS Overview

  • 1. CSS Overview Cascading Style Sheets Svetlin Nakov Manager Technical Training http://nakov.com Telerik Web Design Course html5course.telerik.com
  • 2. Table of Contents  What is CSS?  Styling with Cascading Stylesheets (CSS)  Selectors and style definitions  Linking HTML and CSS  Font and text styles  Backgrounds  Colors and images 2
  • 3. CSS: A New Philosophy  Separate content from presentation! Content Presentation (HTML document) (CSS Document) Title Lorem ipsum dolor sit amet, Bold consectetuer adipiscing elit. Suspendisse at pede ut purus Italics malesuada dictum. Donec vitae neque non magna aliquam dictum. Indent • Vestibulum et odio et ipsum • accumsan accumsan. Morbi at • arcu vel elit ultricies porta. Proin tortor purus, luctus non, aliquam nec, interdum vel, mi. Sed nec quam nec odio lacinia molestie. Praesent augue tortor, convallis eget, euismod nonummy, lacinia ut, risus. 3
  • 4. The Resulting Page Title Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse at pede ut purus malesuada dictum. Donec vitae neque non magna aliquam dictum. • Vestibulum et odio et ipsum • accumsan accumsan. Morbi at • arcu vel elit ultricies porta. Proin Tortor purus, luctus non, aliquam nec, interdum vel, mi. Sed nec quam nec odio lacinia molestie. Praesent augue tortor, convallis eget, euismod nonummy, lacinia ut, risus. 4
  • 5. CSS Intro Styling with Cascading Stylesheets
  • 6. CSS Introduction  Cascading Style Sheets (CSS)  Used to describe the presentation of documents  Define sizes, spacing, fonts, colors, layout, etc.  Improve content accessibility  Improve flexibility  Designed to separate presentation from content  Due to CSS, all HTML presentation tags and attributes are deprecated, e.g. font, center, etc. 6
  • 7. CSS Introduction (2)  CSS can be applied to any XML document  Not just to HTML / XHTML  CSS can specify different styles for different media  On-screen  In print  Handheld, projection, etc.  … even by voice or Braille-based reader 7
  • 8. Why “Cascading”?  Priority scheme determining which style rules apply to element  Cascade priorities or specificity (weight) are calculated and assigned to the rules  Child elements in the HTML DOM tree inherit styles from their parent  Can override them  Control via !important rule 8
  • 10. Stile Inheritance  Some CSS styles are inherited and some not  Text-related and list-related properties are inherited - color, font-size, font-family, line-height, text-align, list-style, etc.  Box-related and positioning styles are not inherited - width, height, border, margin, padding, position, float, etc  <a> elements do not inherit color and text- decoration 10
  • 11. Style Sheets Syntax  Stylesheets consist of rules, selectors, declarations, properties and values http://css.maxdesign.com.au/  Selectors are separated by commas  Declarations are separated by semicolons  Properties and values are separated by colons h1,h2,h3 { color: green; font-weight: bold; } 11
  • 12. Selectors  Selectors determine which element the rule applies to:  All elements of specific type (tag)  Those that match a specific attribute (id, class)  Elements may be matched depending on how they are nested in the document tree (HTML)  Examples: .header a { color: green } #menu>li { padding-top: 8px } 12
  • 13. Selectors (2)  Three primary kinds of selectors:  By tag (type selector): h1 { font-family: verdana,sans-serif; }  By element id: #element_id { color: #ff0000; }  By element class name (only for HTML): .myClass {border: 1px solid red}  Selectors can be combined with commas: h1, .link, #top-link {font-weight: bold} This will match <h1> tags, elements with class link, and the element with id top-link 13
  • 14. Selectors (3)  Pseudo-classes define state  :hover, :visited, :active , :lang  Pseudo-elements define element "parts" or are used to generate content  :first-line , :before, :after a:hover { color: red; } p:first-line { text-transform: uppercase; } .title:before { content: "»"; } .title:after { content: "«"; } 14
  • 15. Selectors (4)  Match relative to element placement: p a {text-decoration: underline} This will match all <a> tags that are inside of <p>  * – universal selector (avoid or use with care!): p * {color: black} This will match all descendants of <p> element  + selector – used to match “next sibling”: img + .link {float:right} This will match all siblings with class name link that appear immediately after <img> tag 15
  • 16. Selectors (5)  > selector – matches direct child nodes: p > .error {font-size: 8px} This will match all elements with class error, direct children of <p> tag  [ ] – matches tag attributes by regular expression: img[alt~=logo] {border: none} This will match all <img> tags with alt attribute containing the word logo  .class1.class2 (no space) - matches elements with both (all) classes applied at the same time 16
  • 17. Values in the CSS Rules  Colors are set in RGB format (decimal or hex):  Example: #a0a6aa = rgb(160, 166, 170)  Predefined color aliases exist: black, blue, etc.  Numeric values are specified in:  Pixels, ems, e.g. 12px , 1.4em  Points, inches, centimeters, millimeters  E.g. 10pt , 1in, 1cm, 1mm  Percentages, e.g. 50%  Percentage of what?...  Zero can be used with no unit: border: 0; 17
  • 18. Default Browser Styles  Browsers have predefined CSS styles  Used when there is no CSS information or any other style information in the document  Caution: default styles differ in browsers  E.g. margins, paddings and font sizes differ most often  Usually developers reset them * { margin: 0; padding: 0; } body, h1, p, ul, li { margin: 0; padding: 0; } 18
  • 19. Linking HTML and CSS  HTML (content) and CSS (presentation) can be linked in three ways:  Inline: the CSS rules in the style attribute  No selectors are needed  Embedded: in the <head> in a <style> tag  External: CSS rules in separate file (best)  Usually a file with .css extension  Linked via <link rel="stylesheet" href=" …"> tag  Via @import directive in embedded CSS block 19
  • 20. Linking HTML and CSS (2)  Using external files is highly recommended  Simplifies the HTML document  Improves page load speed as the CSS file is cached 20
  • 21. Inline Styles: Example inline-styles.html <!DOCTYPE html> <html lang="en"> <head> <title>Inline Styles</title> </head> <body> <p>Here is some text</p> <!--Separate multiple styles with a semicolon--> <p style="font-size: 20pt">Here is some more text</p> <p style="font-size: 20pt;color: #0000FF" >Even more text</p> </body> </html> 21
  • 22. Inline Styles: Example inline-styles.html <!DOCTYPE html> <html lang="en"> <head> <title>Inline Styles</title> </head> <body> <p>Here is some text</p> <!--Separate multiple styles with a semicolon--> <p style="font-size: 20pt">Here is some more text</p> <p style="font-size: 20pt;color: #0000FF" >Even more text</p> </body> </html> 22
  • 23. CSS Cascade (Precedence)  There are browser, user and author stylesheets with "normal" and "important" declarations  Browser styles (least priority)  Normal user styles  Normal author styles (external, in head, inline)  Important author styles  Important user styles (max priority) a { color: red !important ; } http://www.slideshare.net/maxdesign/css-cascade-1658158 23
  • 24. CSS Specificity  CSS specificity is used to determine the precedence of CSS style declarations with the same origin. Selectors are what matters  Simple calculation: #id = 100, .class = 10, :pseudo = 10, [attr] = 10, tag = 1, * = 0  Same number of points? Order matters!  See also:  http://www.smashingmagazine.com/2007/07/27/css-specificity-things-you-  http://css.maxdesign.com.au/selectutorial/advanced_conflict.htm 24
  • 25. CSS Rules Precedence Live Demo precedence.html
  • 26. Embedded Styles  Embedded in the HTML in the <style> tag: <style type="text/css">  The <style> tag is placed in the <head> section of the document  type attribute specifies the MIME type  MIME describes the format of the content  Other MIME types include text/html, image/gif, text/javascript …  Used for document-specific styles 26
  • 27. Embedded Styles: Example embedded-stylesheets.html <!DOCTYPE html> <html> <head> <title>Style Sheets</title> <style type="text/css"> em {background-color:#8000FF; color:white} h1 {font-family:Arial, sans-serif} p {font-size:18pt} .blue {color:blue} </style> <head> 27
  • 28. Embedded Styles: Example (2) … <body> <header> <h1 class="blue">A Heading</h1> </header> <article> <p>Here is some text. Here is some text. Here is some text. Here is some text. Here is some text.</p> <h1>Another Heading</h1> <p class="blue">Here is some more text. Here is some more text.</p> <p class="blue">Here is some <em>more</em> text. Here is some more text.</p> </article> </body> </html> 28
  • 29. Embedded Styles: Example (3) … <body> <header> <h1 class="blue">A Heading</h1> </header> <article> <p>Here is some text. Here is some text. Here is some text. Here is some text. Here is some text.</p> <h1>Another Heading</h1> <p class="blue">Here is some more text. Here is some more text.</p> <p class="blue">Here is some <em>more</em> text. Here is some more text.</p> </article> </body> </html> 29
  • 30. External CSS Styles  External linking  Separate pages can all use a shared style sheet  Only modify a single file to change the styles across your entire Web site (see http://www.csszengarden.com/)  link tag (with a rel attribute)  Specifies a relationship between current document and another document <link rel="stylesheet" type="text/css" href="styles.css">  link elements should be in the <head> 30
  • 31. External CSS Styles (2) @import  Another way to link external CSS files  Example: <style type="text/css"> @import url("styles.css"); /* same as */ @import "styles.css"; </style>  Ancient browsers do not recognize @import  Use @import in an external CSS file to workaround the IE 32 CSS file limit 31
  • 32. External Styles: Example styles.css /* CSS Document */ a { text-decoration: none } a:hover { text-decoration: underline; color: red; background-color: #CCFFCC } li em { color: red; font-weight: bold } ul { margin-left: 2cm } ul ul { text-decoration: underline; margin-left: .5cm } 32
  • 33. External Styles: Example (2) external-styles.html <!DOCTYPE html> <html> <head> <title>Importing style sheets</title> <link type="text/css" rel="stylesheet" href="styles.css" /> </head> <body> <h1>Shopping list for <em>Monday</em>:</h1> <li>Milk</li> … 33
  • 34. External Styles: Example (3) … <li>Bread <ul> <li>White bread</li> <li>Rye bread</li> <li>Whole wheat bread</li> </ul> </li> <li>Rice</li> <li>Potatoes</li> <li>Pizza <em>with mushrooms</em></li> </ul> <a href="http://food.com" title="grocery store">Go to the Grocery store</a> </body> </html> 34
  • 35. External Styles: Example (4) … <li>Bread <ul> <li>White bread</li> <li>Rye bread</li> <li>Whole wheat bread</li> </ul> </li> <li>Rice</li> <li>Potatoes</li> <li>Pizza <em>with mushrooms</em></li> </ul> <a href="http://food.com" title="grocery store">Go to the Grocery store</a> </body> </html> 35
  • 37. Text-related CSS Properties  color – specifies the color of the text  font-size – size of font: xx-small, x-small, small, medium, large, x-large, xx-large, smaller, larger or numeric value  font-family – comma separated font names  Example: verdana, sans-serif, etc.  The browser loads the first one that is available  There should always be at least one generic font  font-weight can be normal, bold, bolder, lighter or a number in range [100 … 900] 37
  • 38. CSS Rules for Fonts (2)  font-style – styles the font  Values: normal, italic, oblique  text-decoration – decorates the text  Values: none, underline, line-trough, overline, blink  text-align – defines the alignment of text or other content  Values: left, right, center, justify 38
  • 39. Shorthand Font Property  font  Shorthand rule for setting multiple font properties at the same time font:italic normal bold 12px/16px verdana is equal to writing this: font-style: italic; font-variant: normal; font-weight: bold; font-size: 12px; line-height: 16px; font-family: verdana; 39
  • 40. Fonts Live Demo font-rules.html
  • 42. Backgrounds  background-image  URL of image to be used as background, e.g.: background-image:url("back.gif");  background-color  Using color and image and the same time  background-repeat  repeat-x, repeat-y, repeat, no-repeat  background-attachment  fixed / scroll 42
  • 43. Backgrounds (2)  background-position: specifies vertical and horizontal position of the background image  Vertical position: top, center, bottom  Horizontal position: left, center, right  Both can be specified in percentage or other numerical values  Examples: background-position: top left; background-position: -5px 50%; 43
  • 44. Background Shorthand Property  background: shorthand rule for setting background properties at the same time: background: #FFF0C0 url("back.gif") no-repeat fixed top; is equal to writing: background-color: #FFF0C0; background-image: url("back.gif"); background-repeat: no-repeat; background-attachment: fixed; background-position: top;  Some browsers will not apply BOTH color and image for background if using shorthand rule 44
  • 45. Background-image or <img>?  Background images allow you to save many image tags from the HTML  Leads to less code  More content-oriented approach  All images that are not part of the page content (and are used only for "beautification") should be moved to the CSS 45
  • 46. Background Styles Live Demo background-rules.html
  • 47. CSS Reference  A list of all CSS 2.1 properties is available at http://www.w3.org/TR/CSS2/propidx.html 47
  • 49. Homework 1. Create the following page section using HTML and external CSS (no inline styles). Use a table or a definition list (in this case the layout will be different). 49
  • 50. Homework (2) 1. Create the following Web page using external CSS styles. 50
  • 51. Homework (3) 1. Implement the following using CSS styles 51
  • 52. Homework (4) 1. Implement the following using tables and CSS 52

Editor's Notes

  1. * 07/16/96 (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##