[lesson 2] The syntax of CSS and inheritance

Discussion in 'CSS' started by algerian, Apr 30, 2009.

  1. #1
    Syntax
    The syntax of CSS is very simple: selector (property: value)
    Exemple :
    body { background: #eeeeee; }
    Code (markup):
    Each selector (here body) can have several properties with values independent:
    body { 
     background: #eeeeee; 
     font-family: Trebuchet MS, Verdana, Arial;
    }
    Code (markup):
    There is a semicolon between each property.

    Inheritance
    If we translated the three words of "Cascading Style Sheets are obtained Cascading Style Sheets.

    Why "cascade"?

    Because if you set a font type "Trebuchet MS" <body> on the tag, all other elements of the site take as Trebuchet MS font, no need to redefine each element.

    If you want a different font for the tag <h1> for example, simply define it again.
    h1 {font-family: Georgia, sans-serif;}
    p {font-family: Tahoma, serif;}
    Code (markup):
    Another example, if you définisez body tag with a margin of 20px, the other elements will be 20px by default
    body {margin: 20px;}
    Code (markup):
    Combinaition selectors
    You can also combine the HTML elements that include the same characteristics:
    h1, h2, h3, h4, h5, h6 {
      color: #009900;
      font-family: Georgia, sans-serif;
    }
    Code (markup):
    Make comments 
    Code (markup):
    You can put comments in your code with the following syntax:
    / * Comment here * /
    Code (markup):
    [lesson 1] Introduction to CSS (thread:1327494)
    to be continued
     
    algerian, Apr 30, 2009 IP