views:

443

answers:

3

Hello,

I'm having a minor css issue.

I have a series of layered divs and I've set div class styles and they all show up (padding, font colors,etc). However, the background-color will not work for the overlaying divs.

as a test, I tried to set a border and border styles, and they all worked as well, except the border color, it didn't show up and the border with the extra styling remained black.

Each div has a unique id, and the ones where the background-color are not working are nested (side by side) in a container div. I've been trying to understand if the nested divs are taking the parent divs background color, but I've tried to change the overflow fo the parent, and it didn't have any affect.

As a work around I created a 1 x 1px jpg of the correct background color and set the divs background image, which worked. But it's a hack, and I'm no better off knowing why all the style elements work, except the background-color.

I hope I've explained my situation sufficiently, if anyone can help me I would appreciate it.

(also, as an addition, I use dreamweaver to write code and the background colors show up in the preview mode, but do not show up in firefox, chrome, or IE)

Requested Code:

      <div id="longBox">
        <div id="specialLable"> Rent Specials &amp; promotions</div><!--end specialLable-->
        <div id="promoMain"> 
        <div id="proHeader">Alhambra Village Fall Special:</div><!--end proHeader-->
        <div id="proDate">Expires: Date</div><!--end proDate-->
        <div id="clear"></div>
        <div id="protext">This is where the details go</div><!--end protext-->
        <div id="promoConditions"><br />Limited availability. All promotions subject to change. Not good with other offers or promotions unless specified.</div><!--end promoConditions-->
        <div id="proContact">Request an Appointment</div><!--end proContact-->
        </div><!--end specialLable-->
      </div><!--end longBox-->


#longBox{
width:713px;
height:225px;
background-color:#FFFFFF;
float:left;
margin:1.2em 0 0 .7em;
}

#specialLable{
background-image:url(../images/01titleBar.png);
margin: .5em .5em .5em .5em;
width:689px;
height:30px;
font-size:1.2em;
font-weight:bold;
text-transform:uppercase;
color:#667b90;
padding:3px 0 0 6px;
}


#promoMain{
margin: 0 .5em .5em .6em;
background-color:#ced5da;
height:166px
}

#proHeader{
font-size:11px;
text-align:left;
font-weight:bold;
text-transform:uppercase;
color:#CC6666;
float:left;
padding:.3em .6em .3em .6em;
margin:.6em 0 0 .6em;
background-image:url(/images/images/bgwhite.jpg);
background-repeat:repeat;
width:503px;
}
#proDate{
font-size:11px;
text-align:left;
font-weight:bold;
text-transform:uppercase;
background-image:url(/images/images/bgwhite.jpg);
background-repeat:repeat;
color:#CC6666;
float:right;
width:150px;
padding:.3em .6em .3em .6em;
margin:.6em .6em .6em 0;
}

#protext{
font-size:11px;
text-align:left;
margin:0 .6em 0 .6em;
height:80px;
background:ffffff;
padding:0 0 0 .6em;
background-image:url(/images/images/bgwhite.jpg);
background-repeat:repeat;
}

#promoConditions{
font-size:9px;
text-align:left;
line-height:100%;
float:left;
padding:0 .6em 0 .6em;
margin:.6em 0 0 .6em;
width:503px;
}

#proContact{
font-size:11px;
text-align:left;
font-weight:bold;
text-transform:uppercase;
background-image:url(/images/images/bgwhite.jpg);
background-repeat:repeat;
color:#CC6666;
float:right;
width:150px;
padding:.3em .6em .3em .6em;
margin:.6em .6em 0 0;
}
A: 

Do you have a plugin like Firebug? That can help a lot in showing you any rules that might be overwriting the background color.

Also, make sure you include the # before your hex color numbers. (eg: #ffffff)

...It looks like you're using the id to select the CSS, which is the most specific, so it can only be overridden by: 1) another id selector further down in the CSS, or 2) a selector anywhere in the CSS with both an id and a class or tag name, increasing its specificity. (CSS specificity made simple here)

keithjgrant
A: 

Check your targeting... sometimes the explicit instruction to a class or ID is not enough when it inherits parent attributes.

So like, specifying:

#yourid {background-color: #333;}

might not be enough if its parent has a backgound specified.

You may need to do element.ID like

div#yourid {background-color: #333;}

Catch my drift?

EDIT:

Yeah, I can see the children are inheriting from #longBox. It's best for you to target as I mentioned before. Also, the missing hash/pound/tic tac toe things are required to validate, but most browsers should interpret the malformed CSS ok.

rob - not a robber
A: 

The reason the images are working is because they are new attribs defined to the child. The parent never had an IMG for a BG, so using the 1x1 colored pxel hack will certainly work as you get out of inheritance structure. Anyhow:

Try the following:

     #longBox{
        width:713px;
        height:225px;
        background-color:#FFFFFF;
        float:left;
        margin:1.2em 0 0 .7em;
        }

    div#specialLable{
    background-image:url(../images/01titleBar.png);
    margin: .5em .5em .5em .5em;
    width:689px;
    height:30px;
    font-size:1.2em;
    font-weight:bold;
    text-transform:uppercase;
    color:#667b90;
    padding:3px 0 0 6px;
    }


    div#promoMain{
    margin: 0 .5em .5em .6em;
    background-color:#ced5da;
    height:166px
    }

    div#proHeader{
    font-size:11px;
    text-align:left;
    font-weight:bold;
    text-transform:uppercase;
    color:#CC6666;
    float:left;
    padding:.3em .6em .3em .6em;
    margin:.6em 0 0 .6em;
    background-image:url(/images/images/bgwhite.jpg);
    background-repeat:repeat;
    width:503px;
    }

div#proDate{
    font-size:11px;
    text-align:left;
    font-weight:bold;
    text-transform:uppercase;
    background-image:url(/images/images/bgwhite.jpg);
    background-repeat:repeat;
    color:#CC6666;
    float:right;
    width:150px;
    padding:.3em .6em .3em .6em;
    margin:.6em .6em .6em 0;
    }

div#protext{
    font-size:11px;
    text-align:left;
    margin:0 .6em 0 .6em;
    height:80px;
    background: #ffffff;
    padding:0 0 0 .6em;
    background-image:url(/images/images/bgwhite.jpg);
    background-repeat:repeat;
    }

    div#promoConditions{
    font-size:9px;
    text-align:left;
    line-height:100%;
    float:left;
    padding:0 .6em 0 .6em;
    margin:.6em 0 0 .6em;
    width:503px;
    }

    div#proContact{
    font-size:11px;
    text-align:left;
    font-weight:bold;
    text-transform:uppercase;
    background-image:url(/images/images/bgwhite.jpg);
    background-repeat:repeat;
    color:#CC6666;
    float:right;
    width:150px;
    padding:.3em .6em .3em .6em;
    margin:.6em .6em 0 0;
    }
rob - not a robber
thanks. I think this is the ticket.
Anthony
I can almost guarantee you it was adding `div` to the rules here that did it, rather than the 1px images. You shouldn't need to use a white background image.
keithjgrant
Ah, I see, there's another level of parentage here that I didn't notice at first. Use `background-image: none;` on the children.
keithjgrant