这很可能是重复的,但我找不到任何完全相同的东西。我想在图像下方填充一个空间,以阻止文本完全换行。在视觉方面:
我有这个:
| /---\ 废话 | |图片| 废话 | \---/废话 | 废话 | 废话 | ...
我要这个:
| /---\ 废话 | |图片| 废话 | \---/废话 | 废话 | 废话 | ...
我该怎么办?
你可以这样写:
<img src="bla.png" style="float:left;" />
<div style="overflow:hidden">Some text</div>
您可能需要在这里使用一些 CSS 属性。例如,尝试
display:inline-block;
为图像。或者
float:right;
对于文本和
float:left;
对于图像或两者,. 甚至可以为图像尝试填充底部
更严格的方法是使用表格并将图像和文本添加到同一个 'tr' 中的两个 'td' 元素中
我想你应该设置 img css 向左浮动和文本向右浮动.. 像这样的东西
<img src="bla.png" style="float:left;" />
<div style="float:right;"><p>Some text</p></div>
希望能帮助到你 :)
将 Float 属性添加到图像和文本,将图像添加到 div 中并左对齐并设置 div 高度 = 100%。!我想它会起作用的
如果你的 HTML 是这样的:
<div class="content-container">
<p><img src="whatever" /> text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text </p>
</div>
那么没有办法只用 CSS 来做到这一点。添加一些 jQuery 风格,例如:
// Loop through all the images
$('.content-container img').each(function(){
// Get image height
var imageHeight = $(this).height();
// Get container's height
var containerHeight = $(this).parent('.content-container').height();
// Set image bottom margin to container's height - image height
jQuery(this).css('margin-bottom', (containerHeight - imageHeight) + 'px');
})
HTML:
<div class="content">
<img src="thumbnail.jpg" width="50" height="50" />
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis ligula arcu, luctus nec elementum quis, condimentum a lectus. Suspendisse potenti. Proin neque diam, dictum ac elementum scelerisque, aliquet eget diam....</p>
</div>
CSS:
.content {
padding: 0 0 0 75px; /* 75px being the width of the thumbnail + how much space you want to put between it and your text */
position: relative; /* So the thumbnail is relative to this */
}
.content img {
left: 0;
position: absolute;
top: 0;
}
如果您不介意使用表格,那么您可以轻松解决问题。
像这样:
<table>
<tr>
<td><img src="yourImage.jpg" alt="" /></td>
<td>Your text... blah blah blah..... blah</td>
</tr>
</table>
您可以根据需要设置 td 的宽度,以使所有 td 具有相同的大小。