Log in

View Full Version : Div ID containers and .class attributes?



bassa
10-11-2008, 11:01 AM
Hello!

I have a very simple question to ask.

I mainly use Dreamweaver for creating websites, and I have noticed that some others use Div ID's and classes in the same selector.

Looks like this; #main .lftfloat

The above is a Div ID container named 'main', and a .class attribute named .lftfloat... correct?

My question is then, when people can create the same rules and designs inside the Div ID container, why do they also associate a .class attribute to it, when they really both do the same?


Cheers,
Bassa

TheJoshMan
10-11-2008, 08:40 PM
the class may be a "global" style which they wanted to apply to that certain div. Rather than writing those styles directly to the css for that particular div, they probably just added that class to it as well (which I'm guessing is something which makes the div float left)

vegas1969
10-13-2008, 11:35 AM
sometimes people use the ID as a means to help identify a section.
since an ID can only be used once per page.

Maybe something like #section1, .tab1 and #section2, tab1.
This way, tab1 could have two sets of definitions depending on which ID is controlling that area at the moment.

jimbob79
10-14-2008, 01:04 AM
I agree with Nyne, although the ID is and can be used as a way to help "indentify" a section of the page (hence the name "ID"), I think that Nyne hit the nail on the head when mentioning global styles. Though you can style an ID in css just as you can a class, what if you already have a certain set of styles set in a global class? Why write more code than you have to? It's simpler just to apply that class to the ID than write the styles all over again.

TheJoshMan
10-14-2008, 05:27 PM
that's exactly what I was getting at.