theme development - How to display only the first two elements from ten same elements

admin2025-06-06  7

For example, in my theme, I have the following elements,

<ul>
<li> apple </li>
<li> orange </li>
<li> banana </li>
<li> pear </li>
<li> peach </li>
...
</ul>

I just want to display the first two li elements, how to hide the other ones form the third element?

The given condition to my issue is that, I cannot add any attribute like id or class to li elements.

For example, in my theme, I have the following elements,

<ul>
<li> apple </li>
<li> orange </li>
<li> banana </li>
<li> pear </li>
<li> peach </li>
...
</ul>

I just want to display the first two li elements, how to hide the other ones form the third element?

The given condition to my issue is that, I cannot add any attribute like id or class to li elements.

Share Improve this question asked Oct 29, 2018 at 17:13 p onelandp oneland 171 silver badge8 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

You can css

ul li:nth-child(n+3) {
    display: none;
}

It'll not show 3rd and up.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749223557a317397.html

最新回复(0)