Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

class selectors css 1

Status
Not open for further replies.

waydown

Programmer
Apr 27, 2009
49
GB
Hi,
I came across the following in an example in a book:
.col-left,
.col-right,
.col-wrapper,
.col2-right-layout .col-main
{ float: left
}
Why is comma (,) used to separate some class identifiers and not between .col2-right-layout .col-main. Is this correct or is there an error? Will be grateful for all help.
 
It depends on what exactly the object was of that css.

When you separate class names with a comma, it means the styles will apply to all those classes individually.
i.e An element with a class name of any of them will be floated left.

The last selector, may be wrong, if you want to apply the float to 2 different elements: One with a class of col2-right-layout, and one with a class off col-main.
Code:
<div class="col2-right-layout">
</div>

<div class="col-main">
</div>

However, it would be correct, if what you wanted to do was to apply the float to an element with a class of col-main that is inside an element with a class of col2-right-layout
i.e it would apply to this:
Code:
<div class="col2-right-layout">
[indent]<div class="col-main"></div>[/indent]
</div>

In the first scenario, both divs would be floated.

In the second one only the interior div would be floated, but the outer one would not be.

So the CSS could be both right or wrong depending on what the intended outcome is.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Also don't forget the 3rd possibility.

Perhaps it was trying to reference an element that had both classes applied and the space is erroneous?

Code:
<div class="col2-right-layout col-main"></div>

Which would require this CSS
Code:
.col2-right-layout.col-main {float:left;}

As Vacunita says, it's not possible to tell without knowing the intent or seeing the mark-up it is trying to reference.


"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top