tags:

views:

41

answers:

3

Hi,

I have a div with the following CSS class defined:

<div class="ui-button ui-state-active">bla bla bla</div>

I am trying to define the CSS styling for that class by doing it this way

<style>
    .ui-button .ui-state-active {
        background-color:#000000;
    }
</style>

It's not working, am I referring to the class in the wrong way?

Thanks

+4  A: 

Remove the space:

.ui-button.ui-state-active

with the space, the rule says "elements with the class ui-state-active that are descendants of elements with the class ui-button".

Specifying multiple classes is buggy in IE6: To IE6, the rule will apply to all elements with the class ui-state-active. (Thanks @Meder for the reminder)

Pekka
+1 But just to clarify, by children you mean descendants. Children´s is the > operator. http://www.w3.org/TR/CSS2/selector.html#child-selectors
lasseespeholt
@lasse you're right, cheers. Need to start using that to avoid confusion.
Pekka
What if my the class statement is this:<div class="ui-button ui-state-active ui-other-widgets ui-more-buttons">Do I need to include ALL classes in my css? or will the css statement above work?
Or W
@Or W no, you don't have to specify those classes together like `classname.classname.classname` . You would usually even want to specify them separately! You can also specify classes in the markup that don't exist. It doesn't matter.
Pekka
+2  A: 
.ui-button.ui-state-active {} 

Though this probably won't work in IE6, if that matters.

meder
A: 

Why not just change the class to ui-state-active and copy the css over? (I know it's duplicating code)

<div class="ui-state-active">bla bla bla</div>

<style>
.ui-button {
    background-color:#000000;
}
.ui-state-active {
    background-color:#000000;
    color:blue;
}
</style>
Xavias