Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

class selectors css

class selectors css

class selectors css

I came across the following in an example in a book:
.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.

RE: class selectors css

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.


<div class="col2-right-layout">

<div class="col-main">

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:


<div class="col2-right-layout">
<div class="col-main"></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

RE: class selectors css

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?


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

Which would require this CSS


.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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close