The old ways of changing how your text looks in HTML has been outdated. The new way to do it is by using style sheets. Learning CSS (Cascading Style Sheets) is really worth the efforts involved. One of the reasons is for consistency - you don't have to remember every single detail for each font, alignment and other details. There is also a factor of readability when you are looking at the raw code. It also saves a lot of work. Instead of having to type all the font attributes each time you need to change the formatting, all you have to do is define a simple rule for the concerned tag and it will take care of all your formatting needs.
You can easily make the changes site-wise or for particular place, just by using CSS properly. CSS can be added in a web page as embedded style sheet or as a link for an external sheet. Depending on your use you can utilize any of the two methods. For external style sheet you have to place all the rules in a file with ".css" extension and then you have to link the style sheet to your web page like:
<link rel="stylesheet" href="style.css" type="text/css" />
And for internal styles you need to add the rules between <style> tag, like:
<style type="text/css">
.links {
font-family:Arial;
font-size:12px;
color:gray;
}
</style>
If you require the changes for your whole site then define the specific rule for the concerned tags, for example if you want to change the text for whole site then define a <p> tag for the specific rules that you want your whole site to follow. Say if you require your font family to be Arial, and your font size to be 12 pixel, your font color to be say gray then you should define a rule in your style sheet as following:
p {
font-family:Arial;
font-size:12px;
color:gray;
}
The above rule will be the same for all the <p> tags in your site. If you want to change the formatting of your text any time in the future, then you will only require to modify the above defined lines for your <p> tag.
If you want to make the changes for one place, say one page in your site you can define an id or a class for that specific page or place and make the changes for it in the style sheet. Class or Id is an attribute that you can add to any of your tags, to give them a specific group; just to make your task easy to modify your design and formatting. Class is defined in a style sheet with a preceding dot (.) like:
.leftfont{
font-family:Arial;
}
An Id is defined with preceding # like:
#rightfont{
font-family:Arial;
}
To use any of these ids or class you will have to call them for the respective tag like for <p> you will use <p class="leftfont"> or <p id="rightfont">. You can use a class rule any number of time in a web page, but (to make the markup valid) you can use id only once in a single page. If you want to use same set of use again and again then its better to define it in a class rule.
Friday, January 9, 2009
Why to use CSS for formatting your layout?
Posted by Raj at 9:28 PM
Subscribe to:
Post Comments (Atom)

0 comments:
Post a Comment