• My Cars
  • Ferrari
    Geek Answers Handbook

    How to select some siblings, but not only through CSS?

    <div class="wrapper"> <ul class="cars"> <li class="headline">My Cars</li> <li>Ferrari</li> <li>Hummer</li> </ul> <ul class="cars"> <li class="headline">My Cars</li> <li>Volvo</li> <li>Caddilac</li> </ul> </div> 

    Is there a way to hide the second <li class="headline"> CSS only? I tried several different selector methods like + , > , etc., but to no avail. I am in a position where I do not control the source code, but only CSS. Therefore, please do not suggest using javascript, changing HTML, etc. I just can't change anything except CSS :)

    +4
    html css css-selectors
    Weblurk May 03 '11 at 14:52
    source share
    3 answers

    Each .headline always the first descendant of its containing .cars , so choose siblings based on .cars elements.

    Most likely you want a second .cars :

     /* CSS2 */ .cars:first-child + .cars .headline { display: none; } /* CSS3 equivalent, but for browser compatibility just use the above instead */ .cars:nth-child(2) .headline { display: none; } 
    +8
    Boltlock May 03 '11 at 14:55
    source share

    Yes you can use the CSS3 nth-child selector:

     div.wrapper ul.cars:nth-child(2) li.headline { display: none; } 

    More details here: http://www.quirksmode.org/css/nthchild.html

    0
    Sam huggill May 03 '11 at 14:58
    source share

    CSS3 has an nth-of-type () selector, but MSIE does not support its AFAIK.

    0
    Rostislav Matl May 03 '11 at 15:00
    source share

    More articles:

    • Strange issue of importing Python date and time data - python
    • How to hide a menu item with a custom view? - objective-c
    • SQL Server 2008 R2, possibly creating a new database - sql
    • Python Tkinter font selection - python
    • https://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1350793/how-to-tie-products-to-categories&usg=ALkJrhhWrhVyMoA3FJhlsY-C4MjzzK958Q
    • Replace image on youtube video - youtube
    • Folder Size for Computing - clojure
    • Ruby Unzip String - ruby โ€‹โ€‹| fooobar.com
    • Socket.io error on specific networks - node.js
    • Add real time update to slow page in asp.net - c #

    All Articles

    Geek Answers | 2019