0

Struggling to position the background around the embedded div#'s .. i think it's going to be something tiny i've missed for looking - any ideas?

the blue div border is just there to show me where the columns are while im changing code the div#wrapper (will be a background image when i sort it) - that green is supposed to go behind the embedded div with height adapting accordingly

code on here: http://jsfiddle.net/SparrowWoods/rREAh/689/

<div id="wrapper">
<div id="mainContent">
    <h2>A Start</h2>
                <p>
                Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
                </p>
                <p>
                Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
                </p>
                <h2>A Start</h2>
                <p>
                Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
                </p>
                <p>
                Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
                </p>
</div><!--end main column-->
<div id="sideContent">
    <h2>A Start</h2>
                <p>
                Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
                </p>
                <p>
                Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
                </p>
</div><!--end right column-->
</div><!--end content-->
#wrapper{
    background-color:green;
    height:auto;
    width:100%;
    padding:5%;
    margin-left:10%;
    margin-right:10%;
    position:relative;
}
#mainContent {
    border: 1px solid blue;
    float: left;
    width: 60%;
    height: auto;
    padding:5%;
}
#sideContent {
    border: 1px solid blue;
    float: left;
    width: 25%;
    height: 100%;
    padding:2%;
}
Sparrow Woods
  • 31
  • 1
  • 8

3 Answers3

0

In this case the easiest solution is to use a clearing float underneath the columns:

<br style="clear:both;padding:0">

The problem you have is that you're using float:left to position the columns next to eachother. Because of this, they're taken out of flow layout, effectively making the parent empty as far as the browser is concerned. This is why you only saw it coloring its padding.

Alternative approach would be to position the columns next to eachother with display:inline-block, but that can give some other issues with whitespace showing up in between.

Niels Keurentjes
  • 41,402
  • 9
  • 98
  • 136
0

Add a float:left; to your wrapper element :

#wrapper{
    float:left;
}

http://jsfiddle.net/rREAh/693/

Cana
  • 2,204
  • 1
  • 13
  • 12
  • If it helps you validate please – Cana Jun 10 '13 at 15:14
  • sorry i'm really new here lol whats that/ how do i do it? thanks – Sparrow Woods Jun 10 '13 at 15:38
  • This isn't really a good solution. While it works to solve the immediate problem you're just displacing it. The *float everything* method isn't called that for nothing - while a floating element will resize to properly contain its floating children, you've just displaced the problem - now `#wrapper` has no size and anything below it will have the same issue. It solves the problem at hand, not your layout. – Niels Keurentjes Jun 11 '13 at 08:27
0

The reason the background doesn't cover the divs inside is because they're floated. There are several solutions for this. Two of them are.

  1. Set a fixed height to your contaner div(#wrapper)
  2. Add a div underneath #maincontent and #sideContent that clears all floats clear:both fiddle
Natalie Hedström
  • 2,607
  • 3
  • 25
  • 36