在没有负边距的情况下,最好的方法是制作两个div和两张图片:
答案 0 :(得分:4)
从您的图片中我考虑了以下内容:
HTML:
<div class="item">
<div class="image-wrapper">
<img src="{image source}" alt="{alternate text}" />
</div>
<p>some text</p>
</div>
CSS:
.item {
overflow: hidden;
}
.image-wrapper {
width: 200px; /* or whatever is the max width of the images */
height: 100px; /* or whatever is the height of the images */
float: left;
margin-right: 20px;
text-align: center;
}
.item p {
float: left;
margin: 0;
line-height: 100px;
}
带有演示颜色的工作fiddle。
答案 1 :(得分:4)
HTML
<div>
<img src="yourimage.jpg" align="left" />
<p>some text</p>
</div>
<div>
<img src="yourimage.jpg" align="left"" />
<p>some text</p>
</div>
CSS
div { margin:0 0 20px 0; }
p { padding:4px 0 0 30px; display:inline-block }
我相信这是最好的方式。至少,一种最小的方式。
工作版:
<强>修强>
答案 2 :(得分:3)
为什么没有负边距?
反正:
<div class="div">
<img src="grey.gif" width="60" height="60">
<p>Some text</p>
</div>
<div class="div">
<img src="grey.gif" width="60" height="60">
<p>Some text</p>
</div>
.div {
overflow: hidden;/* Contain the floated image */
margin-bottom: 20px;
}
.div img {
float: left;
margin-right: 30px;
}