1

我正在制作一个正好为 6 个 div 的小布局宽度,我尝试了多次将其与浮动对齐、clear:both 和更改高度/宽度对齐,但没有成功。我想要这样的图像:http: //i.stack.imgur.com/j1jxX.png

HTML 源代码:

    <div id="description">
    <div class="itemDescription"><!--Item 1-->
        <div class="imageDescription"></div>
        <div class="textDescription">
            <div class="titleDescription">Encontre pessoas</div>
            <div class="detailDescription">Encontre facilmente pessoas com um buscador inteligente</div>
        </div>
    </div>
        <div class="itemDescription"><!--Item 2-->
        <div class="imageDescription"></div>
        <div class="textDescription">
            <div class="titleDescription">Encontre pessoas</div>
    <div class="detailDescription">Encontre facilmente pessoas com um buscador inteligente</div>
    </div>
</div>

CSS 源代码:

#description {
width: 96%;
background: rgb(244, 244, 0);
}
.itemDescription {
padding: 8px;
border: solid 1px red;
}
.imageDescription {
float: left;
height: 72px;
width: 20%;
background-image: url(http://addons.opera.com/media/extensions/75/86675/1.0-rev2/icons/icon_64x64.png);
background-position: center center;
background-repeat: no-repeat;
border-right: solid 3px black;
}
.textDescription {
float: left;
width: 70%;
border: solid 3px blue;

}
.titleDescription {
border: solid 3px brown;

}
.detailDescription {
border: solid 3px black;
padding: 10px;
}

这是我的 JSFiddle:http: //jsfiddle.net/5xhQk/

也谢谢大家

4

3 回答 3

1

你也可以使用 table 来获得你想要的,但如果你真的想使用 div,你需要在每个 div 中使用 float。像这样的东西:http: //jsfiddle.net/5xhQk/1/

#description{
  float: left;
  width: 100%;
}

.itemDescription{
  float: left;
  width: 100%;
  height: 72px;
}

.imageDescription{
  background: blue;
  float: left;
  width: 20%;
  height: 100%;
  border: 1px solid black;
}

.textDescription{
  float: left;
  width: 70%;
  height: 100%;
  border: 1px solid black;
  border-left: 0;
}

.titleDescription{
  float: left;
  width: 100%;
  border-bottom: 1px solid black;
}

.detailDescription{
  float: left;
  width: 100%;
}

哦,我不明白为什么在你的图片中它是宽度 20% 和 70%,你打算用剩下的 10% 做什么?

于 2013-01-13T00:11:40.477 回答
0

让我看看我是否明白了,你imageDescriptiontextDescriptionitemDescription

于 2013-01-13T00:21:49.127 回答
0

尝试类似的东西:

HTML:

<div class="itemDescription">
    <div class="imageDescription ">
        Your image
    </div>
    <div class="cl">&nbsp;</div>
    <div class="textDescription">
        some header
        some paragraph
    </div>
</div>

CSS:

.cl{
clear:both;
}
.itemDescription {

    width: something;

}

.imageDescription {

    float: left;
    width: something;
}

.textDescription {
    float: right;
    width: something;
}
于 2013-01-13T00:37:56.983 回答