How to include and apply Css - Reviewed

Author : Pacman View or add comments : (0)
Date : 2005-10-05 05:00 Average members rating : 0
Where do we put the CSS?

We can writte CSS in three different ways:

-*- In a CSS file, the method the most used.
-*- Between the Head tags.
-*- In the tags.


I recomand you to use the first method, to write your css in a css file, with a *.css extention.

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
   <head>
       <title>Example of an External CSS file</title>
       <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
       <link rel="stylesheet" media="screen" type="text/css" href="style1.css" />
   </head>
   <body>
       <p>Some text here</p>
   </body>
</html>


Ok, this is the first method, using a css file.
We will focus on this code:
Code:
<link rel="stylesheet" media="screen" type="text/css" href="style1.css" />


That will search our css file, and then add the properties to the HTML/XHTML document.

The css is added with the tag, wich have many properties,
rel -> that would be stylesheet
media -> don't know what is this, but be sure to set it to media or all.
type -> be sure to chose text/css
href -> where the file is located

The Second method

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
   <head>
       <title>Example of CSS in the Head</title>
       <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
       <style type="text/css">
           /* Write here your CSS code - This is a comment */
tag
{
   property: value;
   property: value;
   property: value;
}

       </style>
   </head>
   <body>
       <p>This page has CSS directly in the header.</p>
   </body>
</html>


We will focus in this code:

Code:
<style type="text/css">
/* Write here your CSS code - This is a comment */
tag
{
   property: value;
   property: value;
   property: value;
}

</style>


The code is between the and tags, and the css is added with the