【发布时间】:2015-06-08 18:37:07
【问题描述】:
我正在尝试将设计转换为 HTML/CSS,图像和文本之间的垂直间距相等,但无法这样做。设计师在图片、标题和 desc 之间创建了 20px 的边距,但由于 CSS 处理行高的方式,所有这些元素之间的空间并不相同。
<div class="teaser-image">
<img src="teaser1.png">
</div>
<div class="teaser-title">At Your Service</div>
<div class="teaser-desc">
blah blah blah
</div>
.teaser-image, .teaser-title, .teaser-desc {
margin-bottom: 20px;
line-height: 21.6px;
}
.teaser-title {
font-family: "myriad-pro-condensed",sans-serif;
font-weight: 700;
font-size: 24px;
text-align: center;
}
.teaser-desc {
font-size: 16px;
font-family: "myriad-pro-condensed",sans-serif;
text-align: center;
}
【问题讨论】:
-
你希望你的输出是怎样的?
-
我希望每个元素下方有 20 像素的边距,并且实际上在浏览器中看起来是这样的。
-
这个问题没有简单的解决方法。您的选择是在每个项目上创建负边距以将它们“减少”到适当的间距,或者根据元素组合具有不同的边距。
-
@JesseKernaghan 我不敢苟同。有一个简单的解决方案。
-
你好,图片的大小是多少,从什么到什么(div 中的任何背景,或边框?) div 到 div 或 text to text to image 的 20px 边距?