stefan and zogo small Help Stefan Campaign
If you can spare $1 then help support this site and change someone's life forever? Learn how and why on the Help Stefan campaign page. Or donate $10 and get my guide to spices book as a gift for your donation!


Celtnet Information:

How to Create your index.html

CeltNet CSS Logo

CSS is an acronym that stands for Cascading Style Sheets. They are important as they separate the content of your websites (defined in HTML) from the layout (which can be defined in CSS). In effect this allows you to write your site's style in a CSS file that can be called by your html page and which is then applied to the page. Obviously, by keeping the style and the HTML separate you're reducing the size of your HTML files (and maling them quicker to laod). You're also able to change the 'look and feel' of your website by simply changing the CSS file. Of course, it's possible to include CSS in the header region of your HTML file (and this can be useful if you want to do something specific to a single page). With CSS you can also define multiple files each defining different styles which you can then apply to various areas or subdomains of your website.

How CSS Works

Above you've had a (very) brief introduction to CSS, but the only real way to see how CSS works is to play with it.

There are styles in HTML as well, these are the things that define the size, style and clour of font or its degree of shading. In traditional HTML these styles are applied to a tag, such as a <font> tag. In CSS all these changes are gathered together under the banner of an unique name, called a selector. The style is then defined as an attribute of that selector (don't worry about the terminology for now, all will become clear) which means that in your CSS file they all occur in one place (this makes them easier to write and to subsequently locate if you need to change them).

When it comes to using the style in your HTML file you simply use the name of the selector as an attribute of the HTML tag that you want to apply the style to, using the class attribute.

The following example should make things clearer:

<table>

<tr><td bgcolor="#99FFCC" align="left"><font face="arial" size="2" color="red"><b>this is line 1</b></font></td></tr>

<tr><td bgcolor="#99FFCC" align="left"><font face="arial" size="2" color="red"><b>this is line 2</b></font></td></tr>

<tr><td bgcolor="#99FFCC" align="left"><font face="arial" size="2" color="red"><b>this is line 3</b></font></td></tr>

</table>


<table>
<tr><td class="bigtext">this is line 1</td></tr>
<tr><td class="bigtext">this is line 2</td></tr>
<tr><td class="bigtext">this is line 3</td></tr>
</table>

The top table defines the classic HTML and the bottom table uses CSS to define the style. You can see from the top table that you're defining the table colum style for each column in the table, which obviously could makes the table code and the HTML file very large. If, however, the style is saved in a CSS file (assuming that you've defined the bigfont selector style in that file) then you can simply refer to that style using the class="bigtext" attribute. You can see that this makes the table much smaller and easier to read and as you only need to define the style once this significantly reduces the size of the files that the user needs to upload and makes the loading of your web pages much quicker.

This is also a good example of the separation of the layout from the content. With this system the HTML file deals only with the content whilst the CSS file defines the layout. CSS also allows you to define very complex layouts fairly simply (the header block, the main text, the left-hand sidebar, the right-hand side-bar and the footer of this web page are defined with pure CSS and HTML there isn't a table in sight. Indeed, header, footer, maintext, leftnavigation and rightnavigation areas are simply defined with those selector keywords. Just use those and you've defined the main areas of your website (which is a lot easier than fiddling with nested tables, right?).

The Advantages of CSS:

As you may have realized by now, I'm a great fan of CSS and below is a list of some of the strengths of CSS:

Overall, your pages will lad faster as you've removed all the duplicate style definitions from your HTML files (making them smaller) and these are now defined only once in a single CSS document. As this document only needs to be loaded once into a web browser this makes the loadig of yor other web-pages quicker, thus giving your visitors a better experience.

I should mention that there is one potential disadvantage, in that CSS only displays correctly in fourth-generation browsers. However, 95% of all browsers now lie in this category. Even without CSS enabled your pages (as they're basically pure HTML) will still load into older browsers (and even text readers) they simply won't be formatted with your CSS styles.

The next part of this CSS course will get you started on thinking about CSS and actually writing your own CSS code for the first time. If you are interested in following this course, of if you want to brush-up your CSS programming skills then I suggest that you buy yourself a book on CSS and HTML (a number of possible options form Amazon are shown at the bottom of this page).

On to the next part...

Bestsellers


In association with Amazon.com
  

Sorry, we are currently unable to process your request in a timely manner. Please try amazon.com

 



Domain Name Registration




Quick Links:
Make Money from the Web
Essential Web Tools
Generate your Website
Paid Surveys
Affiliate Programmes
Successful Affiliates
Maximizing Traffic
News Feeds
Using Minisites
Form-mail script
Sitemap
Links
Celtnet Information Home


Site Search





[Valid RSS] Register Domains
Copyright © 2005–2007, Dyfed Lloyd Evans