简体   繁体   中英

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">

<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.

Like so:

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

Just select li is not first-child.

use :not for is not , and use first-child to select first element.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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