Tuesday 18 December 2012

What is external css ?

When using CSS it is preferable to keep the CSS separate from your HTML. Placing CSS in a separate file allows the web designer to completely differentiate between content (HTML) and design (CSS). External CSS is a file that contains only CSS code and is saved with a ".css" file extension. This CSS file is then referenced in your HTML using the 'link' instead of 'style'.

File creation


Let us get started by making that external CSS file. Open up notepad.exe, or any other plain text editor and type the following CSS code.

CSS Code:

 body{ background-color: 9FF;}
 p { color: blue; }
 h3{ color: red; }
Now save the file as a CSS (.css) file. Make sure that you are not saving it as a text (.txt) file, as notepad likes to do by default. Name the file "test.css" (without the quotes). Now create a new HTML file and fill it with the following code.

HTML Code:



Then save this file as "index.html" (without the quotes) in the same directory as your CSS file. Now open your HTML file in your web browser and it should look something like this..

Display:

A Red Header

This paragraph has a blue font. The background color of this page is sky blue because we changed it with CSS!

No comments:

Post a Comment