views:

49

answers:

4

Hi, I have code blindness, it's like snowblindness, just wth far too much code.

I have a div class dynamically generated,

<div class="even last"> 

How can I select that with CSS?

div.even last {
    background-color:#ffffff;
    height:100%;
    border-top:1px solid #F5F5F5;
    padding:2px;
    margin-top:35px;
}

Doesn't seem to work, and I just can't think more..

Thanks :)

+4  A: 

You cannot have spaces in a css class name. This should work:

<div class="even_last"> 

div.even_last {
    background-color:#ffffff;
    height:100%;
    border-top:1px solid #F5F5F5;
    padding:2px;
    margin-top:35px;
}

Spaces in css mean: the next element contained in the previous one, for example:

<div class="even_last">
    <div>
        Hello
    </div>
    World
</div>

div.even_last div {
    font-weight:bold;
}

Hello will be bold, while World will not.

Philip Daubmeier
Yes, but as I said, it's gerneated, so I can't change the HTML to produce the underscore :)
Kyle Sevenoaks
You probably want to preserve the existing classes though. Both even and last are fairly standard when dealing with lists and tables.
CurtainDog
Oh, I see. Then 'ck's answer will do for you.
Philip Daubmeier
+7  A: 

When multiple classes are specified with a space, it applies both of those classes to the element.

Therefore if you specify div.even AND/OR div.last it will use them.

ck
+3  A: 

Replace the space with a dot and you're right:

div.even.last {
    background-color:#ffffff;
    height:100%;
    border-top:1px solid #F5F5F5;
    padding:2px;
    margin-top:35px;
}
CurtainDog
This didn't work either..
Kyle Sevenoaks
I did a quick test page for this, and it styled the div, but nothing after that div would display at all.
ck
Well, it is setting the height to 100%... without the HTML there's no point in speculating what it'll do. But this is the correct selector for matching div elements that are both 'even' and 'last'
CurtainDog
A: 

Name your class like evenlast:

div.evenlast
{
  /* styles here */
}
Sarfraz
Sorry, this didn't work.
Kyle Sevenoaks