SCSS:不(:Last-Child),但样式仍然应用于最后一个元素

发布于 2025-02-13 20:24:04 字数 1211 浏览 0 评论 0原文

我有一个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:

enter image description here

enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

木槿暧夏七纪年 2025-02-20 20:24:04

孩子们是父母的。在您的情况下,最后一个孩子是&lt; div class =“ panel”&gt;。一个
更好的措辞将是:元素必须是最后一个元素,无论选择器如何。

.accordion:not(:last-child) {
  border-bottom: 1px solid darkgray;
}
<div class="parent">
  <div class="accordion">hi</div>
  <div class="accordion">hi</div>
  <div class="accordion">hi</div>
</div>

The children are of the parent div. And in your case, the last-child is <div class="panel">. A
better wording would be: The element must be the last element, regardless of selectors.

.accordion:not(:last-child) {
  border-bottom: 1px solid darkgray;
}
<div class="parent">
  <div class="accordion">hi</div>
  <div class="accordion">hi</div>
  <div class="accordion">hi</div>
</div>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文