PDA

View Full Version : [TUT] Introduction to CSS



Aflux
07-06-2007, 08:03 PM
OK, so if you know basic to advanced (x)HTML then you should be ready to learn CSS which is very nifty when you want to style something.

CSS stands for Cascading Stylesheets and it basically is used for styling things such as tables, text's, div's and layers.

OK, so to make your first CSS document open up Notepad [or any other text/html editor] and save the empty document as "style.css".

Right, to start any CSS code we need to call it something and open it with a "{"

Type this;

body {
}


Now, the body element is used for the whole document and contains such things as backgrounds, alignments and font colour's.

Things you can add are;


body {
background-color: #000000;
color: #FFFFFF;
}

The background-color element is basically what the background colour of the page will be and the color element is the font colour that will be used on the page. After each element, you need a semi colon ";" and start a new line once finished that element.

I'm not going to go into too much detail about all the element's as there really are thousands so I'll just move swiftly on.

If you want to style a div and the div id is "mainbox" then you would have to use the id tag and the name, i.e;

#mainbox {
background-color: #000000;
color: #FFFFFF;
}

Notice the # infront of mainbox? This means that it's the ID of the div and can only be used once whereas classes can be used numerous times and these shall look like this;

.mainbox {
background-color: #000000;
color: #FFFFFF;
}

That's basically it for a start, you've learnt the basics.

I'm not very good at writing tutorials so I'll probably brush up on it later on in life.

=]

:Edzy
07-06-2007, 08:04 PM
nice +REP

Ini
07-06-2007, 08:07 PM
Good tut, you could of wrote it a few days ago though when i need help lol instead i had to search for ages to find out what i needed to no

Aflux
07-06-2007, 08:09 PM
It's only the very basics and not very well written.

Mr.OSH
07-06-2007, 08:11 PM
A nice tutorial for beginners, well done. :) + rep.

Puma
07-06-2007, 08:29 PM
nice TUT..

Ini
07-06-2007, 08:52 PM
A nice tutorial for beginners, well done. :) + rep.

Exactly me ;]

:Edzy
07-06-2007, 08:59 PM
It's only the very basics and not very well written.

the modisty. ;P

RYANNNNN
07-06-2007, 09:36 PM
I reccomend you just use background: so you can use more things such as repeat-x/y, colors, images etc.

Tom H
07-06-2007, 09:43 PM
Nice one.

Mentor
08-06-2007, 03:11 PM
Wait? im confused, how is it possible to use xhtml WITHOUT css? Youd be left with absoulty no formating control ??

Aflux
08-06-2007, 03:33 PM
Wait? im confused, how is it possible to use xhtml WITHOUT css? Youd be left with absoulty no formating control ??
Unformatted.

It is possible.

Mentor
08-06-2007, 03:35 PM
Unformatted.

It is possible.
How is a long line of text considered useing xhtml? u would have more formating control if it were just a txt document?

Aflux
08-06-2007, 03:43 PM
How is a long line of text considered useing xhtml? u would have more formating control if it were just a txt document?
It would be a mess and unformatted and basically horrible but with a little application you could.

Sygon..
08-06-2007, 07:53 PM
Addon Tips:

"background-url:", "background-color" etc. Isnt really good to use as its just more code adding and making your file bytes bigger.

Do it like:




body

{

background: #000000 url(images/image.jpg); no-repeat;

}



For example and try to keep css files clean with comments and good formatting




/* CLASSES MULTIPLE USE*/

.class

{

width: 100px;

}

/* ID USED ONCE */

#id

{

width: 100px;

}

Mentor
08-06-2007, 08:43 PM
Just as a note i dont think you want that ; in the middle of your background attributes.

Luckyrare
08-06-2007, 08:55 PM
Although you say basic, this is to basic. Explain it so they can create something nice/useful rather than something basic. Nice work anywho ;)

Sygon..
09-06-2007, 10:10 AM
Just as a note i dont think you want that ; in the middle of your background attributes.

Yeh the habbox editor was hard to work with >.>

redtom
09-06-2007, 11:07 AM
I can code in CSS & XHTML but I still don't get why your not suppost to use an ID more then once, can any one inlighten me?

Luckyrare
09-06-2007, 11:10 AM
I can code in CSS & XHTML but I still don't get why your not suppost to use an ID more then once, can any one inlighten me?

If you use # thats for the id attribute, if you use . thats for the class attribute. If you need to use something more than once then you use class

Mentor
09-06-2007, 03:45 PM
I can code in CSS & XHTML but I still don't get why your not suppost to use an ID more then once, can any one inlighten me?

Becuse an id is a unquie reference to an item, say for when useing javascript when you want to target somthing specific.
If you want a attrbiute set for a more genral useage just use a class.

Ajax.
09-06-2007, 11:14 PM
Basic but helps :)

Want to hide these adverts? Register an account for free!