Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 如何删除具有特定类名的最后一个div的边框?[:最后一个孩子]不工作_Css - Fatal编程技术网

Css 如何删除具有特定类名的最后一个div的边框?[:最后一个孩子]不工作

Css 如何删除具有特定类名的最后一个div的边框?[:最后一个孩子]不工作,css,Css,我尝试删除类名为“true”的最后一个子级的边框:最后一个子项不工作 <div> <div class="common true">1111</div> <div class="common">2222</div> <div class="common true">3333</div> <div class="common true">4444</div>

我尝试删除类名为“true”的最后一个子级的边框<代码>:最后一个子项不工作

<div>
    <div class="common true">1111</div>
    <div class="common">2222</div>
    <div class="common true">3333</div>
    <div class="common true">4444</div>
    <div class="common true">5555</div>
    <div class="common true">6666</div>
    <div class="common true">7777</div>
    <div class="common">8888</div>
</div>

jsiddle:

您应该使用js来解决它。使用css,您可以使用
最后一个子项
最后一个类型
,但在这种情况下,它们无法解决问题,因为:

:last-child选择器匹配作为其父元素最后一个子元素的每个元素

在你的情况下,
.true
不是最后一个孩子

:last of type选择器匹配作为父元素的特定类型的最后一个子元素的每个元素

在您的情况下,所有元素都是
div
,并且您不能使用
最后一个类型选择具有特定类的div

您可以尝试:

$(".true").last().css( "border-top", "none" );

类型选择器的
:last允许您将元素在其容器中的最后一次出现作为目标

.true:last-of-type {
    border-top: none;
} 

CSS没有选择器来选择具有特定类的最后一个元素。它只有
最后一个子项
最后一个类型
。在这种情况下两者都不起作用。你需要使用JS。(相关线程-和)。我没有投票决定以重复方式关闭,以防您想要编辑和接受JS/jQuery答案。如果您可以在最后一个true元素7777和css.common.true.last{border top:0 none;}中添加一个类,谢谢您的回答。但是我想用CSS。在CSS中有什么方法可以做到这一点吗?:last of type selector只选择元素而不是类
。true:last of type
表示它使用true class选择最后一个元素。true是类而不是元素,这就是它不起作用的原因。p:last of type或div:last of type都不起作用。true:last of type
.true:last-of-type {
    border-top: none;
}