【发布时间】:2023-04-02 21:22:02
【问题描述】:
这是我的CLOSED QUESTION 的副本,但副本无关紧要
但它不看类,只看类型,所以如果你碰巧有非同一个类的文章,你会得到意想不到的结果
Second "duplicate" 完全是另外一回事。
Third "duplicate" 解释了为什么我的尝试不起作用。
Fourth "duplicate" 给出了第一个元素的解决方法,而不是最后一个元素。
我知道没有 CSS 选择器,我只是想要一个解决方案。在结束我的问题之前请注意这一点!
我有 5 个按钮。正如您将在 sn-p 中看到的那样,它们有一个底层,使它们看起来很活跃。
每个按钮都可以有一个活动状态,但只能从 1 开始,到 5 为止。
它们都有一个分隔线,在 sn-p 中显示为红色。
我想将分隔线保留在底层中,在底层之外,但我想让它在底层的末端消失(在 sn-p 中,在按钮 #2 之后)。
在我的第一个问题之后,我了解到没有 CSS 选择器可以做到这一点。那么解决这个问题的最佳方法是什么?
.container {
display: flex;
align-items: stretch;
justify-content: start
margin: 12px;
position: relative;
}
button:after {
content: '';
height: 100%;
position: absolute;
background: red;
left: calc(100% + 12px);
width: 1px;
top: 0;
}
button.active:last-child:after {
content: none;
}
button {
flex: 0 0 calc(20% - 24px);
border: 0;
height: 32px;
color: black;
text-transform: uppercase;
text-align: center;
margin-right: 24px;
background: transparent;
position: relative;
}
button.active {
color: white;
}
.active-pill {
background: teal;
position: absolute;
height: 32px;
border-radius: 16px;
background: teal;
width: calc(40% - 12px);
z-index: -1;
}
<div class="container">
<div class="active-pill"></div>
<button class="active">Step 1</button>
<button class="active">Step 2</button>
<button>Step 3</button>
<button>Step 4</button>
<button>Step 5</button>
</div>
<h3>
Which selector to use to remove the content after button #2 ?
</h3>
【问题讨论】:
-
你为什么不把按钮包装在一个 div 上然后玩这个:developer.mozilla.org/en-US/docs/Web/CSS/:nth-of-type
-
@M4FI4S 因为问题还是一样,然后我必须找到
div.active。
标签: css css-selectors pseudo-element