【发布时间】:2020-01-24 23:22:39
【问题描述】:
我想为 span 元素设置不同的边距。例如,margin-top: 25px 应该是第一个 span 元素,margin-top: 15px 应该是第二个元素:
<div style="background: green">
<span style="display: inline-block; margin-top: 25px;">1</span>
<span style="display: inline-block; margin-top: 15px;">2</span>
</div>
但是,第二个span 有margin-top: 25px。
是否可以为两个span 元素设置不同的margin-top?
【问题讨论】:
-
是什么让你认为他们现在没有这个?
-
他们都站在同一个基线上,你可以重置垂直对齐或使用浮动或弹性
-
@G-Cyr 你能用
flex显示代码吗? -
只需将 display:flex 添加到父级(绿色背景)。有用的链接css-tricks.com/snippets/css/a-guide-to-flexbox
-
@G-Cyr 非常感谢您!:) 它有效!我真的很惭愧!点赞!