|
|
|
|
![]() ![]() |
Jan 12 2006, 06:57 PM
Post
#1
|
|
|
A computer once beat me at chess, but it was no match for me at kick boxing. ![]() Group: [MODERATOR] Posts: 4,071 Joined: 24-July 05 From: Linix, DOS and Windows…the good, the bad and the ugly Member No.: 9,787 ![]() |
Multiple Classes in Css Styles
Classes are used in html pages to give certain defined attributes to elements. They are useful when the attributes are to be used in more than one place on a page. (Named Id's are only allowed once per page, but I digress... might have a tutorial on that some day.) Sometimes you want Red text and sometimes you want Bold text. Easy enough to do, simply define a class and apply it to the element you want red or bold. Use this class where you want on the page, since classes are enabled to be used in several spots, for different uses on a page. Meaning you could apply the class to h3 tags and selected spans, for example. CODE .red {color:red} .bold{font-weight:bold;} Once in a while, you want Red and Bold text. Does this mean you must define a third class and use it? Nope. Css allows you to apply multiple classes to the same element by including both (in this example) classes to the element. CODE <p class= "red bold">red and bold</p> Be sure to leave 'white space' between the class descriptors or the method will fail. ie: a minimum of one blank space between 'red' and 'bold'. Here is a sample link to show whether it will work in your browser. Notice that this file shows the Multi-class being used in both paragraph and span tags, and twice on the page as classes are designed to do. This code has been tested and confirmed working in the following Browsers: Opera8, Mozilla 1.7.3, IE5 Win, and IE5 Mac, with no hacks required, so it should work in most browsers. Multi-class Link Here Listing of the Sample file contents: HTML <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>Multi-class Tutorial Html</title> <style type="text/css"> .red {color:red} .bold{font-weight:bold;} </style> </head> <body> <p class= "red">red</p> <p class= "bold">bold</p> <p class= "red bold">red and bold</p> <span class= "red bold";>red and bold</span> </body> </html> I hope this is helpful. |
|
|
|
Jan 12 2006, 10:25 PM
Post
#2
|
|
|
Princess ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 1,233 Joined: 9-October 04 From: England Member No.: 1,563 |
oh wow. I actually didn't know you could do that.. Can you do it using the "id" thing aswell? I know you can do the
E.G CODE #content td {color:black} #content #mini {color:white} html code CODE <table id="content"><tr><td id="mini">example</td></tr></table> I think it's the same, although I don't know. It might be wrong because I usually don't understand the html I write. |
|
|
|
Jan 12 2006, 11:11 PM
Post
#3
|
|
|
A computer once beat me at chess, but it was no match for me at kick boxing. ![]() Group: [MODERATOR] Posts: 4,071 Joined: 24-July 05 From: Linix, DOS and Windows…the good, the bad and the ugly Member No.: 9,787 ![]() |
Becca,
I modified that sample file above to include your css and code. I added one td tag also, to show that the first css descriptor does actually work. Your css changes the colour of the first table cell because of the reference to the id = mini for the cell. The cell next to it reverts back to black because of the first line of your css where the td's colour if defined. The id=mini can only be used once on each page, whereas the class = red can be applied as many times as you want. That is a signifigant difference between using the id= and the class=. Any guess to what would happen when id= mini and class=bold? So now the first cell has id=mini (to make it red) and class = bold (to make it bold), so it could be done using both an id and a class. Except, it can only be done once on a page, and we now have three things to deal with. One name-id and two classes. If we drop the name-id, it can all be done with the two original classes anyway, so how come the single use id??? I would use classes only. |
|
|
|
Jan 14 2006, 08:05 PM
Post
#4
|
|
|
Princess ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 1,233 Joined: 9-October 04 From: England Member No.: 1,563 |
wow. That is um... pretty confusing...
plus why is there a gap after the = and ; CODE <span class= "red bold";>red and bold</span> |
|
|
|
Jan 14 2006, 09:38 PM
Post
#5
|
|
|
A computer once beat me at chess, but it was no match for me at kick boxing. ![]() Group: [MODERATOR] Posts: 4,071 Joined: 24-July 05 From: Linix, DOS and Windows…the good, the bad and the ugly Member No.: 9,787 ![]() |
white space is ignored in html and the ";" is out of place, but it parses okay, so no worries. This post has been edited by jlhaslip: Jan 14 2006, 09:42 PM |
|
|
|
Jan 15 2006, 05:12 PM
Post
#6
|
|
|
Privileged Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 629 Joined: 26-February 05 Member No.: 3,995 |
Wow, I thought I was good at CSS, and I didn't know that was possible. This will be very helpful in the future. Thanks!
|
|
|
|
Jan 15 2006, 05:30 PM
Post
#7
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 286 Joined: 4-December 05 From: Latvia, Riga Member No.: 15,337 |
Nice and detailed tutorial.. I have never tryed anything like that but I will definatly try something like that
|
|
|
|
Jan 15 2006, 07:14 PM
Post
#8
|
|
|
Member [Level 1] ![]() ![]() ![]() ![]() Group: Members Posts: 56 Joined: 15-January 06 Member No.: 17,166 |
If you new at HTML you could go here http://www.funkychickens.com/html.html that site really helped me. They are realllllllllllly out dated and i mean REALLY outdated lol but other than that its a good site to teach you.
Here is some info about their site QUOTE About Funky Chickens HTML Help! Funky Chickens was created in December 1999, to help teach HTML (HyperText Markup Language). HTML is made up of special codes that add the effects that make your website colorful, cool, and professional looking. We have divided the codes into sections to make it easier to find them. There is an index & glossary for you to locate and understand the various codes. If you have a specific problem, try checking out the "Questions" section. We really appreciate your coming to our site, we believe our site will be a useful reference. This post has been edited by BuffaloHELP: Jan 16 2006, 01:39 AM |
|
|
|
Jan 25 2006, 01:58 PM
Post
#9
|
|
|
Privileged Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 535 Joined: 14-February 05 From: Oslo, Norway Member No.: 3,759 |
Wow, I actually didn't know that. Does it work in all browsers supporting CSS?
Anyway, thanks alot, I'm sure that will help me!! |