简体   繁体   English

使用 CSS 选择器隐藏每个 div(在 ul/li 内),除了第一个

[英]Hide every div (inside ul/li) with CSS selector except first one

How to hide with CSS every <div class="rpwwt-post-excerpt"> in my UL/LI list except first one, but to keep all <span class="rpwwt-post-title">如何使用 CSS 隐藏我的 UL/LI 列表中除第一个之外的每个<div class="rpwwt-post-excerpt"> ,但保留所有<span class="rpwwt-post-title">

<div id="rpwwt-recent-posts-widget-with-thumbnails-2" class="rpwwt-widget">
<h4 class="widget-title penci-border-arrow"><span class="inner-arrow">WIDGET TITLE</span></h4>
    <ul>
        <li>
            <span class="rpwwt-post-title">TITLE #1</span>
                <div class="rpwwt-post-excerpt">POST EXCERPT TO SHOW</div>
        </li>
        <li>
            <span class="rpwwt-post-title">TITLE #2</span>
                <div class="rpwwt-post-excerpt">POST EXCERPT TO HIDE</div>
        </li>
        <li>
            <span class="rpwwt-post-title">TITLE #3</span>
                <div class="rpwwt-post-excerpt">POST EXCERPT TO HIDE</div>
        </li>
        <li>
            <span class="rpwwt-post-title">TITLE #4</span>
                <div class="rpwwt-post-excerpt">POST EXCERPT TO HIDE</div>
        </li>
    </ul>
</div>

Inside your selector use the :not(:first-child) pseudo-class on the ancestor li to exclude the first <li> in a list from matching the selector - even though the style-rule ultimately affects only div.rpwwt-post-excerpt elements.在您的选择器中,使用祖先li上的:not(:first-child)伪类将列表中的第一个<li>排除在匹配选择器之外 - 即使样式规则最终只影响div.rpwwt-post-excerpt元素。

Like so:像这样:

li:not(:first-child) div.rpwwt-post-excerpt {
    display: none;
}

Just select li is not first-child.只是选择 li 不是第一胎。

use :not for is not , and use first-child to select first element.使用 :not for is not ,并使用 first-child 选择第一个元素。

so , ul li:not(:first-child) { display:none;所以,ul li:not(:first-child) { display:none; } }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM