gpt4 book ai didi

css - 在元素和边框之间应用间距

转载 作者:行者123 更新时间:2023-11-28 17:26:50 27 4
gpt4 key购买 nike

demo

html:

<span id="foo">foo</span>

CSS:

#foo{
background: #f00;
display: inline-block;
border-top: 5px solid #000;
margin-top: 20px;
}

但是 margin-top 应用于整个元素。我想要红色背景和黑色边框之间的空间。

我已经用 :before pseudo 试过了,但是我必须给边框宽度,这不是个好主意,因为 #foo 元素的宽度可能会有所不同。

最佳答案

我想你可以试试 :before to ge link

 span:before{ border-top: 5px solid #000;display:block;content:"";margin-top:-6px;}

关于css - 在元素和边框之间应用间距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27031690/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com