在段落之间,您应该margin为该元素设置一个。您可以在段落内的行之间使用line-height。例如:
p {
line-height: 32px; /* within paragraph */
margin-bottom: 30px; /* between paragraphs */
}
Run Code Online (Sandbox Code Playgroud)
添加 margin-bottom: 30px 可以解决问题,但您也或多或少地锁定了最后一段下方的下一个元素的间距,也以 30px 间距开始。段落之间的间距可能会与段落本身的行高匹配(或接近),这可能与下一类型元素的间距不同。
例如,假设您有一个对话框,其内容区域末尾有一个段落,下一个元素是对话框的页脚区域(带有操作按钮)。如果创建的反向边距超出了对话框内容和页脚之间的预期值,那么您不会希望执行一些反向负边距。
p {
line-height: 32px;
&:not(:last-child) {
margin-bottom: 30px;
}
}
// or space on top with a sibling selector:
p {
line-height: 30px;
+ p {
margin-top: 32px;
}
}
////
// or if your line-height and paragraph spacing is the same:
////
$p-line-height: 30px;
p {
line-height: $p-line-height;
&:not(:last-child) {
margin-bottom: $p-line-height;
}
}
// w/ space on top:
p {
line-height: $p-line-height;
+ p {
margin-top: $p-line-height;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21440 次 |
| 最近记录: |