【发布时间】:2021-05-22 18:43:59
【问题描述】:
我试图在锚点/按钮周围制作边框,但不知何故 z-index 在以下代码中不起作用,即使我为它们中的任何一个分配了位置。 它在一定程度上与负 z-index 一起工作(但其他伪类,如 :hover 等将不起作用 -> 请参阅我的最后一个问题),但有人可以解释为什么 ::before 伪元素一直显示在按钮上方而不是下方?
这是我的代码:
.start-coding {
display: block;
font-size: 1.3rem;
color: white;
background-color: black;
padding: 0.4rem 1.8rem;
position: relative;
z-index: 5;
border-radius: 5px;
width: 100%;
}
.start-coding::before {
content: '';
background: linear-gradient(115deg, #4fcf70, #fad648, #a767e5, #12bcfe, #44ce7b);
border-radius: 5px;
position: absolute;
top: -3px;
left: -3px;
right: -3px;
bottom: -3px;
z-index: 1;
}
<a href="#" class="start-coding">Start Coding</a>
【问题讨论】:
-
这个网站解释了原因:independent-software.com/… 顺便说一句,还有一件事,
:hover不适用于::after和::before,因为实际上它们是虚构的元素。
标签: html css z-index pseudo-element