最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin10PV0评论

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.

Post a comment

comment list (0)

  1. No comments so far