Cascading Style Sheets (CSS) - How to?

Few things to remember when using CSS, is different browsers handle the code in different ways.... i'll give you an example...

Code:
<table class="example">
<tr>
<td>Content</td>
</tr>
</table>

Code:
.example {
width:100%;
border: 1px solid #000;
background-color: #fff;
text-align: center
}

Now firefox would render this as a table that spans the whole page with a white background and no padding, text centered etc...

However, unless you specify padding:0 Internet Explorer assumes a default amount of padding (3 or 4 pixels i think of the top my head).

Why IE does this i don't know, so you may find that you need to check whatever you work in different browsers and make a few additions to the code as IE likes to assume certain things when they are not present.

So to account for IE, you'd do this...

Code:
.example {
width:100%;
border: 1px solid #000;
background-color: #fff;
text-align: center;
padding:0
}

Its not always padding IE does this with though, sometimes you may find text aligns differently unless it is directly told where to align to.

Also...... here's a few things.....

Code:
font {color: #000}
Code:
.font {color: #000}
Code:
#font {color: #000}
First one redefines the HTML tag font.
The second is a class named font. (class="font")
The third is an id named font. (id="font")

Id's if i remember correctly can only be used once per page, so you shouldnt use an ID where it will load on a page more then once, where as a CLASS can be used as many times as you like throughout the page.
 
Back
Top Bottom