Home About Us FAQ Free Articles Submit Trusted Websites/Articles Privacy Policy Contact Us

Search
  



Trusted Websites
Exim Turkey B2B Marketplace, E...
EC21, Global B2B Marketplace -...
Sound Level Meters and Vibrati...
Drink Vending and Snack machin...
Lead Nurturing Lead Dogs...
DPT Fast Rapid Prototyping...
Envision Telephony, Inc.: Call...
Scheduling Software & Asset Ma...
TriNet Total HR Services...
Wine distributors importers pr...
Medgarde: Medical Transcriptio...
Trade Show Display...
Tyvek clothing and protective ...

 

 

 

 

 

 

Applying Css to Html
Home » Tutorials » Html »

Author: ExcellentGuide
Added: October 31, 2006

Applying CSS


There are three ways of applying CSS to HTML.


In-line


In-line styles are plonked straight into the HTML tags using the style attribute.


They look something like this:


<p style="color: red">text</p>

This will make that specific paragraph red.


The approach of HTML Dog is that the HTML should be a stand-alone, presentation free document, and so in-line                         styles should be avoided wherever possible.


Internal


Internal styles are used for the whole page. Inside the head tags, the style tag surrounds all of the styles for the page.


This would look something like this:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>CSS Example</title>
<style type="text/css">
p {
color: red;
}

a {
color: blue;
}
</style>
...

This will make all of the paragraphs in the page red and all of the links blue.


Similarly to the in-line styles, you should keep the HTML and the CSS files separate, and so we are left with our saviour...


External


External styles are used for the whole, multiple-page website. There is a separate CSS file, which will simply look something like:


p {
color: red;
}

a {
color: blue;
}

If this file is saved as 'web.css' then it can be linked to in the HTML like this:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>CSS Example</title>
<link rel="stylesheet" type="text/css" href="web.css" />
...

In the CSS Advanced Guide, we will see that there are other ways of linking external style sheets, but this will suffice for now.


To get the most from this guide, it would be a good idea to try out the code as we go along, so start a fresh new file with your text-editor and save the blank document as 'web.css' in the same directory as your HTML file.


Now change your HTML file so that it starts something like this:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>

<head>

<title>My first web page</title>

<link rel="stylesheet" type="text/css" href="web.css" />

</head>
...

Save the HTML file. This now links to the CSS file, which is empty at the moment, so won't change a thing. As you work your way through the CSS Beginner's Guide, you will be able to add to and change the CSS file and see the results by simply refreshing the browser window that has the HTML file in it, as we did before.



 

 

 

Home Link to Us Our Partners Contact Us

                                                                                   -- Site Pro News      ComputerScripts.com - Free & Commercial Web Scripts!      Ex-design.net