Monday, March 14, 2011

Basic CSS Syntax

One declaration can contain many rules. An example of a style declaration: 

selector{style-rule;}
A style rule defines the value for a specified property , an example of style rules:
property:value;

Proper CSS syntax is:  
Selector{property:value;}

Selectors
A tag selector is reference to an HTML tag. The subsequent style rules will influence every occurrence of that particular tag. All HTML tags can be used as selectors.
Example of tag selectors:
<a>, <table>, <td>, <body>, <p>, <h1>

A class selector refers to a class of elements. A class is a custom name you can assign to any HTML tag by using the class attribute. Here is how to call the class mentioned below in this document:
.myClass{background-color:#C00;}

Pseudo-selectors are predefined "classes" e.g:
a:link, a:hover, a:visited

Relevant extra HTML
To link to your style sheet: <link rel="stylesheet" type="text/css" href="">

A link with class: <a href="somewhere" class="myClass">
A paragraph with class: <p class="myClass">

Contextual selectors
problem: you want to style all links inside table cells identically. All links outside your table data cells should be styled differently. Contextual selection is the solution, e.g.:

/* following declaration styles only links inside any td*/
td a{text-decoration: none;}

/* following declaration styles all links not specified by other declarations*/
a {background-color: #ff3;}



Assorted CSS properties and values
Box
    • width:[number]px; e.g.: width:200px;
    • height:[number]px;
    • margin:[number]px;
    • padding: [number]px;
    Table
    • vertical-align: top/bottom;
    Miscellaneous
    • display: block/inline;
    • border: [number] px solid/dotted #[color in hexadecimals];
    Text
    • color: #[colorspecified in hexadecimals];
    • font-family: [font name]/serif/sans-serif;
    • font size: [number]%; or px;
    • text-decoration: none/underlined;
    Background
    • background-image: url(' [a path and file name']);
    • background-color: #[color specified in hexadecimals]);
    •  
    PS: All the [ ] sign must be removed together with the text inside.

      0 comments:

      Post a Comment

       
      Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Grants For Single Moms