SCSS:不(:Last-Child),但样式仍然应用于最后一个元素
我有一个DIV,其中包含不同的按钮和其他Divs作为手风琴。 除最后一个按钮外,我想给所有的按钮底部。
UI和html看起来像这样:
href =“ https://i.sstatic.net/qvm8g.png” rel =“ nofollow noreferrer”>
我已经尝试使用:not(:last-Child)
选择器,但是作为您可以在第一个屏幕截图中看到它不起作用,最后一个按钮仍然具有边界底。
.accordion {
background-color: #eee !important;
color: #444;
cursor: pointer;
padding: 18px;
width: 100%;
text-align: left;
border: none;
outline: none;
transition: 0.4s;
}
.accordion:not(:last-child) {
border-bottom: 1px solid black;
}
<button class="accordion">Test</button>
<button class="accordion">Test</button>
<button class="accordion">Test</button>
<button class="accordion">Test</button>
<button class="accordion">Test</button>
(也是
。
提前致谢
I have a div that contains different buttons and other divs working as a accordion.
I want to give all the buttons a border-bottom except for the last one.
The UI and html looks like this:
And I've tried using the :not(:last-child)
selector, but as you can see in the first screenshot it isn't working and the last button still has the border-bottom.
.accordion {
background-color: #eee !important;
color: #444;
cursor: pointer;
padding: 18px;
width: 100%;
text-align: left;
border: none;
outline: none;
transition: 0.4s;
}
.accordion:not(:last-child) {
border-bottom: 1px solid black;
}
<button class="accordion">Test</button>
<button class="accordion">Test</button>
<button class="accordion">Test</button>
<button class="accordion">Test</button>
<button class="accordion">Test</button>
(Also the snippet in JsFiddle)
What am I doing wrong here?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
孩子们是父母的。在您的情况下,最后一个孩子是
&lt; div class =“ panel”&gt;
。一个更好的措辞将是:元素必须是最后一个元素,无论选择器如何。
The children are of the parent div. And in your case, the last-child is
<div class="panel">
. Abetter wording would be: The element must be the last element, regardless of selectors.