Forum Moderators: not2easy

Message Too Old, No Replies

background-color not filling entire box

         

jebadoa

8:13 am on Aug 17, 2008 (gmt 0)

10+ Year Member



I have a div that contains a header, an image, and some text. The image is floated left, and the text is to the right of it. The image is taller than the text block. The trouble is, the background color stops where the text stops, not where the image stops. Incidentally, the border does not show in IE7 either. Noob needs help.

.entry {
background-color:#FFFFEE;
outline:2px solid #750082;
margin-top:10px;
margin-bottom:10px;
padding:3px 3px 8px 3px;
height:auto;
clear:both;
}
.entry img{
float:left;
position:relative;
z-index:1;
}
.title {
font-size:x-large;
background-image:url(../images/Bkgd2.gif);
background-color:#D8CBD8;
padding:inherit;
color:#4A004C;

}
.post {
height:100%;
padding-top:5px;
font-size:larger;
color:#4A004C;
}
.date {
font-size:small;
font-style:italic;
text-align:right;
}

<div class="entry">
<div class="title">Title of the post
<div class="date">date of post</div>
</div>
<div class="post"><img class="alignnone"
title="title of pic"
src="http://etc" alt="alt val" width="200" height="260" />"
Text content
</div>
</div>

Marshall

8:56 am on Aug 17, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



jebadoa, Welcome to WebmasterWorld.

If the entire <div> is suppose to have the background color of #D8CBD8, then it will not fill as you desire as the <div> ends before the image and text. Your html needs changed to:

<div class="entry">
<div class="title">Title of the post
<div class="date">date of post</div>
<div class="post"><img class="alignnone"
title="title of pic"
src="http://etc" alt="alt val" width="200" height="260" />"
Text content
</div>
</div> <!-- This is the end tag for the .title div -->
</div>

As for the border, I assume you are speaking of the .entry <div>. Your css is wrong:

.entry {
background-color:#FFFFEE;
border:2px solid #750082;
margin-top:10px;
margin-bottom:10px;
padding:3px 3px 8px 3px;
height:auto;
clear:both;
}

You do realize that with your padding settings in the .entry, you will get a 3px white gap between your border and background color. Just an FYI.

Marshall

csuguy

9:07 am on Aug 17, 2008 (gmt 0)

10+ Year Member



If I recall correctly - you can fix this fairly simply. First add a div with a class of 'clearer' (or w/e u want) to the post div.

So your html should look like this:


<div class="entry">
<div class="title">Title of the post
<div class="date">date of post</div>
</div>
<div class="post">
<img class="alignnone" title="title of pic" src="http://etc" alt="alt val" width="200" height="260" />
Text content
<div class="clearer"></div>
</div>
</div>

Now add this to your css:


.clearer
{
height: 1px; /*0px might work too*/
clear: both;
}

That should cause it to work!

csuguy

9:16 am on Aug 17, 2008 (gmt 0)

10+ Year Member




If the entire <div> is suppose to have the background color of #D8CBD8, then it will not fill as you desire as the <div> ends before the image and text. Your html needs changed to:

I popped his code into a html file and I saw how he wanted to display it - and it works fine. No need for corrections on this point. I didn't test the border issue though.