在CSS3中,是否可以将背景色应用于而不是应用于边框的元素?
当你使用:
element { background: red; }
背景颜色也适用于边界地区。
发布于 2016-12-13 22:37:42
是
使用background-clip - MDN Link
背景剪辑CSS属性指定元素的背景(无论是颜色还是图像)是否在其边框下扩展。
背景延伸到边界的外部边缘(但在z顺序的边框下面)。
在边框下面没有绘制背景(背景扩展到填充的外部边缘)。
背景在(剪裁到)内容框内绘制。
p {
border: 10px navy;
border-style: dotted double;
margin: 1em;
padding: 1em;
background: #F8D575;
}
.border-box {
background-clip: border-box;
}
.padding-box {
background-clip: padding-box;
}
.content-box {
background-clip: content-box;
}<p class="border-box">The yellow background extends behind the border.</p>
<p class="padding-box">The yellow background extends to the inside edge of the border.</p>
<p class="content-box">The yellow background extends only to the edge of the content box.</p>
发布于 2016-12-13 22:56:53
只需使用:
element { background: red; border-color:black; }https://stackoverflow.com/questions/41131721
复制相似问题