HTML5 APPLICATIONS DEVELOPMENT MANUAL

(lu) #1

14 - CSS Sintax


There are two parts to a CSS rule:



  • selectors

  • declarations


The selectoris usually the HTML element you want to style.


Thedeclarationis the style for a specific selector.



  • declarations have two parts: a property followed by a colon (:) and a space,


and a value followed by a semicolon (;)



  • declarations sit between curly brackets {}


The main types of CSS selectors are:



  • element selector (HTML) such as p, h1, table, etc.
    h1 {
    color: red;
    font-family: sans-serif;
    text-align: left;
    }

  • class selector like .happy, which include a decimal (.) as a prefix
    .happy {
    font-size: 14px;
    }

  • id selector such as #para1, which include a hashtag symbol (#) as a prefix
    #para1 {
    background-color: green;
    }


Note: Id and class are both universal attributes.


Id is used to identify unique elements, class should be used to


categorize elements into groups that will be styled similarly.

Free download pdf