I love CSS I can't live without it lol I use css on every single website I make, and I feel it is one of the most
imporant things I could have learned to make my site better!
There are several different points I will discuss about CSS:
1. What is CSS?
2. How to make a style sheet to change font, backgrounds, links, etc...
3. External Style Sheets
4. Creating layouts using CSS (in a new thread)
What is CSS?
CSS stands for Cascading Style Sheet. CSS lets you define HTML elements such as font, images, colors, backgrounds, links, etc... You can even link to an external style sheets, and make everything so much easier because it allows you to change the code on one page and have it affect your entire site if you want!
CSS can save you time and energy and let you make a great site quickly and easily.
With CSS you can say all font inside a table will be blue, and the only thing it will affect is font you put
inside a table. So you do not have to go through and put <font color="blue"> for every table on every page
of your site!
CSS also makes it really simple to update your pages look without changing the content. You just go through
and change the colors, fonts, etc... You can change one page and it will effect your entire site!
This will just touch on CSS and give you the basic understanding and how to use it.
CSS basics
Creating the Style Sheet
Put your style sheet inbetween the <head></head> tags!
To begin start with this:
<style type="text/css">
This says that you will begin a style sheet using css.
the closing tag is: </style>
Now you need a selector, a property and a value:
It will look like this:
selector {property: value}
the selector is what you want to define such as, p, body, td, etc...
the property is what you want to change such as, font-family, color, background, etc...
the value is the attribute you want it to take on such as, blue, verdana, etc...
So its the selector first, then { then the property then : then the value then }
if you have multable values you seperate them with this ;
a:link is the normal link how it looks when someone first comes to your page.
a:visited is the link after it has been clicked by the person, I usually leave it the same as the first one but
you can change it to make it stand out so people know which links they have already clicked on. It is helpful.
a:active this affects the link when it is clicked on. So if they click on a link to open a new window to another site, and you have the a:link color set to red, and the a:active link set to blue. Once the link was clicked on it would turn blue.
a:hover this affects the link when the mouse is over it.
You must keep it in that order!
You can define any color you want to it. You can make them all have the same color, or each one different.
For text-decoration you have several choices of what to put:
none means it looks like normal text (no line udner it like a normal link). underline means it looks like a normal link, it has a line under it. overline means there is a line above the link underline overline means there is a line above and under the link line-through means there is a slash through the link
So lets say you want a link to have a line above it at first, when it has been visited to have a line through it,
when it is active to have a line above and under it and when the mouse hovers over it you want it to have
Now lets say you wanted to have more then one kindof link on the same page. So on your page you want the links to be like what we did above, but for your navigation you want them all to be one color and no lines at all?
You would first add the code above. Then you would add this:
and then in each link for the navigation you would add: class="nav"
like this:
<a class="nav" href="link.html">Home</a>
You can change the word nav to whatever you want, a.bob:link and then it would be class="bob" it doesn't matter. But using a word like nav will make it easier to find what goes with what lol.
Adding the link style to your style sheet
So right now we have:
<style type="text/css"> body { font-family: verdana; font-size: 11px; color: red } </style>
Adding Background Images and Color June 09, 2005 4:10 PM
To set a background color for the entire page you put:
body { background: #000000 }
To set a background image you put:
body { background-image:url(july4.jpg); background-repeat:no-repeat; background-position:top left; background-attachment:fixed }
background-image:url() is where you put the url of the image you want to use.
background-repeat: you can put repeat, no-repeat, repeat-x, repeat-y if the image is small and you want it to just show up once, to go all the way across or up and down, or not repeat at all.
background-position: where you want it to align, first you say the first value which is either top, bottom, center, percent (100%, 75%) or pixel number so you can tell it exactly how and where you want it (100px) then the second value which is either: right, left, center, percent (100%) or pixel (100px)
background-attachment: do you want the screen to scroll or just the text? if just the text then put fixed if the screen then put scroll.
Now lets add our background to our Style Sheet, place it with the rest of the body{}:
We want to remove the <style type="text/css"></style> tags. Then copy the rest and save it by itself to whatever name you want but make it end with .css so for example style.css
I love using CSS also. I would suggest that when you have as many CSS tags as you show that using and external CSS sheet is more appropriate. What an external CSS gives you is that you can have the CSS codes affect all of your web pages in a site. To create the CSS you save it as a .css file, such as:
myCSS.css
To make this accessible to your web pages you put the following code in between the <head> and </head> tags.