views:

52

answers:

4

I try to make web site with minimal HTML markup for presentation.
Having the following HTML tag:

<div class="title">I'm a title!</div>

I need to add two elements before it using CSS, 1 for background and 1 for shadow. Something like:

.title
{
    display: block;
    position: relative;
}
.title:before
{
    display: block;
    background-color: #00FFFF;
    position: absolute;
    width: 100%;
    height: 100%;
    margin: 0 0 0 0;
    left: 0;
    top: 0;
    content: '';
    z-index: -1;
    opacity: 0.5;
}
.title:before
{
    display :block;
    background-color: #111111;
    position: absolute;
    width: 100%;
    height: 100%;
    margin: 5px -5px -5px 5px;
    left: 0;
    top: 0;
    content: '';
    z-index: -1;
    opacity: 0.5;
}

doesn't work because the second .title:before overrides the first. I cant add the background to the element because I need it to have opacity. Is there any way to do this without adding additional markup? And if the answer is somehow not using two :before elements is there any way to specify more then one?

A: 

I am not sure. Have you tried something like .title:before:before? Maybe this helps... Not able to test it right now.

faileN
Tested it and it doesn't work.
Dani
A: 

why don't use backgroungd gradient image instead

you call then Something like

background : url("../images/image_path.png") 0 0 no-repeat;
Salil
I'm trying to build a site without "hacks" like this one.
Dani
I wouldn't say using background-image is a hack :-)
richsage
[Additional upvote for what rich wrote]
annakata
solid color background image isn't hack? and what about transparent 1 pixel images for sizing? its the same.
Dani
A: 

I dont understand why you cant just use...

.title
{
    display: block;
    position: relative;
    background-color: #00FFFF;
}
.title:before
{
    display :block;
    background-color: #111111;
    position: absolute;
    width: 100%;
    height: 100%;
    margin: 5px -5px -5px 5px;
    left: 0;
    top: 0;
    content: '';
    z-index: -1;
    opacity: 0.5;
}
barrylloyd
because i need opacity on the background but not on text
Dani
Im confused. Do you mean transparency (rather than opacity) ?
barrylloyd
I don't know what's the term.I mean it will blent with the background.
Dani
A: 

Not sure how you'd apply n elements, but for only two (and especially here) it seems to me you could just use :after for the second element...

annakata
I know, but I was kind of hoping to get solution that would fit for n elements.
Dani