0

I'd like for my blog container to have a separate background from the page as a whole. However, it is taking on wood.png as a background not bg.png. I'm using the following:

CSS

body {
 background: url('img/bg.png') repeat;
}
.above {
 background: url('img/wood.png') repeat;
 width: 100%;
}
#blog-header {
 background: url('img/wood.png') repeat; 
 height: 160px;
 width: 100%;
 text-align: center;
}
#blog-container {
 background: url('img/bg.png') repeat;
 margin: 0 auto;
 width: 960px;
}
#blog {
 float: left;
 margin-top: 80px;
 position: relative;
 width: 620px;
}

HTML/PHP

<body>
<div class="above">
 <div id="blog-header">
  <div class="logo">
   <a href="<?php bloginfo('url'); ?>"><img src="<?php echo get_template_directory_uri(); ?>/img/logo.png" alt="Urban Palate logo" id="logo" /></a>
   </div><!-- end logo -->
   <nav>
    <ul>
     <li><a href="/?page_id=7"><img src="<?php echo get_template_directory_uri(); ?>/img/about.png" alt="Urban Palate intro" /></a></li>
     <li><a href="/?page_id=12"><img src="<?php echo get_template_directory_uri(); ?>/img/portfolio.png" alt="Urban Palate portfolio" /></a></li>
     <li><a href="/?page_id=15"><img src="<?php echo get_template_directory_uri(); ?>/img/blog.png" alt="Urban Palate blog" /></a></li>
     <li><a href="/?page_id=10"><img src="<?php echo get_template_directory_uri(); ?>/img/contact.png" alt="Urban Palate contact" /></a></li>
    </ul>
   </nav>
   </div><!-- end blog-header -->
   <div id="blog-container">
    <div id="blog">
     <div id="post">
       //content
     </div><!-- end post -->
    </div><!-- end blog -->
   </div><!-- end blog-container -->

Any ideas what could be causing the issue?

ETA: JSFiddle

Krish
  • 2,590
  • 8
  • 42
  • 62
AMC
  • 1,603
  • 11
  • 43
  • 74

2 Answers2

1

If an element is containing floating element, the wrapping element then needs a overflow:auto or a clear:both; to get the height it needs to add background to it.

In your case you can add either the overflow:auto or the clear:both to #blog-container or you can add it as a separate class as shown below:

Here's a few nice lines you can use to add a clearfix declaration to your css, the you can add that class to any element that has floating elements in it:

/*
 * Clearfix: contain floats
 *
 * For modern browsers
 * 1. The space content is one way to avoid an Opera bug when the
 *    `contenteditable` attribute is included anywhere else in the document.
 *    Otherwise it causes space to appear at the top and bottom of elements
 *    that receive the `clearfix` class.
 * 2. The use of `table` rather than `block` is only necessary if using
 *    `:before` to contain the top-margins of child elements.
 */

.clearfix:before,
.clearfix:after {
    content: " "; /* 1 */
    display: table; /* 2 */
}

.clearfix:after {
    clear: both;
}

/*
 * For IE 6/7 only
 * Include this rule to trigger hasLayout and contain floats.
 */

.clearfix {
    *zoom: 1;
}

The clearfix is taken from: Html5Boilerplate

And here is an extra nice question talking about the clearfix differences: which method of clearfix is best (check answer two)

Community
  • 1
  • 1
Krycke
  • 3,106
  • 1
  • 17
  • 21
  • Don't really need a `clear:both`; `overflow:auto` is enough to make the container expand to contain it's floated children. – Tieson T. Sep 30 '12 at 18:44
0

You may need to set some padding on your body (or set the div width to 95% instead of 100%). It looks like the div is going to take up the full width of the screen.

Adam Plocher
  • 13,994
  • 6
  • 46
  • 79