tags:

views:

44

answers:

2

I am writing a CSS stylesheet to add a background image to a div identified by its class name as follows:

.scrollingResultsContainer
{
    background-image: url(https://mdl0133/widget/Images/gradient.gif);
    background-repeat: repeat-x; 
    background-attachment: fixed;
    color:#FFFFFF;
}

This work fine except I have one particular situation where I do not want the image to appear in the scrollingResultsContainer. How can I specify that the image should be applied except when the scrollingResultsContainer happens to contain a div with a particular id?

Unfortunately I am unable to amend the markup to prevent this situation occurring. I was wondering if it can be done using css3 selectors.

A: 

Over-ride it in the CSS if you know the ID in advance.

.scrollingResultsContainer {
    font-size: 200%;
}

#id_of_div {
    font-size: normal;
}
Martin Bean
Thanks but this is not what I am after. I need to reset the whole of the scrollingResultsContainer not just one particular div within it.
Si Keep
+2  A: 

You can't do this with CSS. A parent selector has been proposed many times but is always rejected because apparently it's just too hard to code or something: http://www.css3.info/shaun-inman-proposes-css-qualified-selectors/

You'll have to use javascript I'm afraid.

Litso
I thought I almost had it by declaring position on the scrollingResultsContainer and using a css before selector like: div#particular_id:before { position:absolute; left:0; right:0; top:0; bottom:0; background:#fff; content:""; } but it completely obliterates everything in the area; even stuff that comes after in the document.
Noel Walters
:before adds a pseudo-element before the div, but does not apply to it's parent.
Litso
true. but you can style the pseudo element using absolute positioning to completely overlay the parent element. unfortunately it also overlays the element that it is applied to - which doesn't make sense to me if it is inserted before it.
Noel Walters
Hmm, I see what you did there. Nice thinking, but too bad indeed that it didn't work. Probably because it's absolute positioning..?
Litso