How to select the first, second, or third element with a given class name?

后端 未结 7 2196

How can I select a certain element in a list of elements? I have the following:

my text
相关标签:
7条回答
  • 2020-11-27 15:09

    use nth-child(item number) EX

    <div class="parent_class">
        <div class="myclass">my text1</div>
        some other code+containers...
    
        <div class="myclass">my text2</div>
        some other code+containers...
    
        <div class="myclass">my text3</div>
        some other code+containers...
    </div>
    .parent_class:nth-child(1) { };
    .parent_class:nth-child(2) { };
    .parent_class:nth-child(3) { };
    

    OR

    :nth-of-type(item number) same your code

    .myclass:nth-of-type(1) { };
    .myclass:nth-of-type(2) { };
    .myclass:nth-of-type(3) { };
    
    0 讨论(0)
提交回复
热议问题