Dex
Dex

Reputation: 12749

CSS Layout Issue + Sample Image


I'm trying to do something like in the image. The container (which contains all three gray rectangles) is 100% the width of the window. Whatever I do, the title and description keep shifting to the left side of the container when it gets too long.

I want the image (which will be a fixed width) to always be in the top left. The title and description should stay within the bounds of the rectangles as shown and their width should expand with the size of the window when resizing.

Here's the fiddle http://jsfiddle.net/hHjeH/

Desired CSS Layout HTML

<div class="container clearfix">
    <div class="image">
    </div>
    <div class="subcontainer clearfix">
        <div class="title clearfix">
            Title
        </div> 
        <div class="description">
            Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. 
        </div>
    </div>
</div>

CSS

.container 
{
  width: 100%;
  margin: 0px;
  padding: 0px;
  background-color:#eee;
}
.image 
{
  width: 100px;
  height: 100px;
  background-color:#888;
  float: left;
}
.subcontainer 
{
  margin: 20px 0px 20px 20px;
  float: left;
}
.title 
{
  font-size:20pt;
  font-weight:bold;
  padding: 0px 0px 10px 0px;
}
.description 
{
  margin-left: 10px;
}
/* For modern browsers to clear floats */
.clearfix:before,
.clearfix:after {
  content:"";
  display:table;
}
.clearfix:after {
   clear:both;
}
/* For IE 6/7 (trigger hasLayout) */
.clearfix {
  zoom:1;
}​

Upvotes: 0

Views: 128

Answers (1)

Labu
Labu

Reputation: 2582

Float the image, and not the .subcontainer. And pad the .subcontainer wider than the image.

Like so: http://jsfiddle.net/hHjeH/2/

Upvotes: 3

Related Questions