2

How to style element after element? For example i have this:

<ul>
  <li>A</li>
  <li class="hiden">B</li>
  <li>C</li>
  <li>D</li>
  <li class="hiden">E</li>
  <li class="hiden">E</li>
  <li class="hiden">E</li>
  <li>F</li>
</ul>

I want every first li after li.hiden to have border-top.

li + li.hiden works only on first element in ul.

enter image description here

3 Answers 3

4

To target first li after li.hiden you should use li.hiden + li selector:

li.hiden + li {
    border-top: 1px red solid;
}
<ul>
  <li>A</li>
  <li class="hiden">B</li>
  <li>C</li>
  <li>D</li>
  <li class="hiden">E</li>
  <li>F</li>
</ul>

Sign up to request clarification or add additional context in comments.

1 Comment

li.hiden + li:not(.hiden) is what i wanted, thanks for help :)
0

This will help you..

https://jsfiddle.net/0c5eu92w/

    li.hiden + li{border-top:1px solid #ccc;}

Comments

0

What about CSS3 selector? Try this:

:nth-child(2n)

You'll find more information here.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.