DIV类的最后一个孩子(last-child of div class)

2019-08-01 15:37发布

我整理了一些WordPress的网页,我想样式(与CSS )项中的轧辊Posts页面。 WordPress的创建此:

<div class="entry">

有在页面这些元素的负荷,分开他们,我在进入底部边框使用。 问题是,我不希望在最后一个进入这个边界。 可以像在CSS做了什么? (请注意,这不是一个列表,所以我不能使用伪类)

这里是我的CSS,这是很简单的:

.entry{  border-bottom: 1px solid yellow; }

HTML:

<div id="wrapper">
  <br />
  there are loads of code
  <br />
  <div class="entry">bunch of code there</div>
  <br />
  <div class="entry">bunch of code there</div>
  <br />
  <div class="entry">bunch of code there</div>
  <br />
  another huge code
  <br />
</div>

在此先感谢您的帮助。

Answer 1:

您已经命名了,你在找什么: last-child : http://reference.sitepoint.com/css/pseudoclass-lastchild

因此,使用.entry:not(:last-child) { border-bottom: 1px solid yellow; } .entry:not(:last-child) { border-bottom: 1px solid yellow; }

需要注意的是it's不是一个列表,所以我不能用伪类)

JSYK,该伪类不依赖于包含元素是一个列表。 如果你的意思是,最终.entry元素实际上并不是其容器的最后一个孩子,它仍然有可能选择它。 但是,除非你告诉我实际的标记是什么样子,我不能告诉你如何。

如果最终div.entry后面没有任何其他的div,然后选择.entry:not(:last-of-type)会为你工作。



Answer 2:

.entry:last-child {
  border-bottom: none;
}

比方说,你有一个列表<li>的链接<a>里面,你想,去年<a>的的<li>的。 只需使用:

.entry:last-child a {
  border-bottom: none;
}

这将选择在最后的.entry和目标它的链接(S)



Answer 3:

很简单的解决方案:

#wrapper :last-child
{
    border:none;
}


Answer 4:

对于最全面的浏览器的支持,我会建议使用这样的:

.entry { border-bottom: 1px solid yellow; }
.entry:last-child { border-bottom: 0; }


文章来源: last-child of div class