Victor
Victor

Reputation: 14583

The DIV won't fit everything inside it

I have the following div that renders wrongly:

enter image description here

The HTML is the one below:

<div class="content-wrapper"> 
  <img src="res/img/Logo.png" id="logo" />
  just regular content
  <ul class="mini-gallery">
    <a href="#"><li><img src="res/img/gallery/bucuresti/17.jpg"></li></a>
    <a href="#"><li><img src="res/img/gallery/bucuresti/10.jpg"></li></a>
    <a href="#"><li><img src="res/img/gallery/bucuresti/3.jpg"></li></a>
  </ul>
</div>

The CSS:

.content-wrapper {
  -webkit-box-shadow: 0px 0px 20px 0px rgba(0, 0, 0, 0.8);
  -moz-box-shadow: 0px 0px 20px 0px rgba(0, 0, 0, 0.8);
  box-shadow: 0px 0px 20px 0px rgba(0, 0, 0, 0.8);
  text-align: left;
  background-color: #E6B5E9;
  width: 960px;
  margin-left: auto;
  margin-right: auto;
  padding-left: 10px;
  padding-right: 10px;
  min-height: 100%;
}

ul.mini-gallery {
  margin-left: 0;
  margin-right: 0;
  margin-bottom: 0; 
  margin-top: 10px;
  padding: 0;
  list-style: none; 
}
ul.mini-gallery li
{   
  list-syle: none;
}
ul.mini-gallery img
{
  width: 310px;
  height: auto;
  margin-right:10px;
  padding: 0;
  float:left;
  border: none;
}

As you might have understood, the images should be within the div, not outside it. So why happens this and how can I solve it?

Upvotes: 0

Views: 585

Answers (3)

Justin
Justin

Reputation: 1329

As suggested above, overflow:auto or a clearfix (what I've done below) will do it. I've also adjusted your HTML so that your anchors are children of your list elements and not the other way around:

<div class="content-wrapper"> 
    <img src="res/img/Logo.png" id="logo" />
    just regular content
    <ul class="mini-gallery">
        <li><a href="#"><img src="res/img/gallery/bucuresti/17.jpg" /></a></li>
        <li><a href="#"><img src="res/img/gallery/bucuresti/10.jpg" /></a></li>
        <li><a href="#"><img src="res/img/gallery/bucuresti/3.jpg" /></a></li>
    </ul>
    <div style="clear:both"></div>
</div>

Here's a fiddle: http://jsfiddle.net/2uMDK/

Upvotes: 2

j08691
j08691

Reputation: 207891

Because you float the images. To allow the container .content-wrapper div to contain them again, add overflow:auto; to it.

.content-wrapper {
    -webkit-box-shadow: 0px 0px 20px 0px rgba(0, 0, 0, 0.8);
    -moz-box-shadow: 0px 0px 20px 0px rgba(0, 0, 0, 0.8);
    box-shadow: 0px 0px 20px 0px rgba(0, 0, 0, 0.8);
    text-align: left;
    background-color: #E6B5E9;
    width: 960px;
    margin-left: auto;
    margin-right: auto;
    padding-left: 10px;
    padding-right: 10px;
    min-height: 100%;
    overflow:auto;
}

Upvotes: 1

jmore009
jmore009

Reputation: 12923

The issue is floating elements without clearing them. You can use a clearfix or just set overflow: hidden on .content-wrapper

JSFIDDLE

Upvotes: 2

Related Questions