admin管理员组文章数量:1399499
I have a dynamic number of ul.column
and some of these have the disabled
class. For example:
<ul class="column"></ul>
<ul class="column"></ul>
<ul class="column disabled"></ul>
I don't know how many I can have, but I want to apply a border-right
to the last .column
which doesn't also have the .disabled
class.
I've tried something like:
ul:not(.disabled):last-child {border-right:1px solid black}
and
ul:last-child:not(.disabled) {border-right:1px solid black}
but the style always applies to the last element, regardless of the :not(.disabled)
selector. Is there another way to style the last .column
that doesn't also have the .disabled
class?
I'm fine using jQuery, but I don't know how achieve what I want.
I have a dynamic number of ul.column
and some of these have the disabled
class. For example:
<ul class="column"></ul>
<ul class="column"></ul>
<ul class="column disabled"></ul>
I don't know how many I can have, but I want to apply a border-right
to the last .column
which doesn't also have the .disabled
class.
I've tried something like:
ul:not(.disabled):last-child {border-right:1px solid black}
and
ul:last-child:not(.disabled) {border-right:1px solid black}
but the style always applies to the last element, regardless of the :not(.disabled)
selector. Is there another way to style the last .column
that doesn't also have the .disabled
class?
I'm fine using jQuery, but I don't know how achieve what I want.
Share Improve this question edited May 13, 2016 at 12:30 Chris 59.6k20 gold badges120 silver badges142 bronze badges asked May 13, 2016 at 12:10 valerio0999valerio0999 12.1k7 gold badges32 silver badges57 bronze badges 02 Answers
Reset to default 8This isn't possible with just css selectors. You could use jQuery though.
Demo
$('ul:not(.disabled):last').css('border-right', '1px solid black');
<script src="https://ajax.googleapis./ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<ul class="column">
<li>test</li>
</ul>
<ul class="column">
<li>test</li>
</ul>
<ul class="column disabled">
<li>test</li>
</ul>
You can select the last ul tag in jQuery, check if it is disabled and apply your styling if appropriate as follows:
if(!$('ul').last().hasClass('disabled')){
$('ul').last().css('border-right', '1px solid black');
}
本文标签: javascriptcss lastchild with not selectorStack Overflow
版权声明:本文标题:javascript - css last-child with :not selector - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744168168a2593650.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论