Select :first-child or :last-child that doesn't contain some specific class

前端 未结 3 788
一个人的身影
一个人的身影 2021-01-21 22:35

Assume we\'re having a list with 5 items and we want to apply some specific styles to the first or the last child. But the functionality of this list will requi

3条回答
  •  情歌与酒
    2021-01-21 22:55

    You can add specific style to first visible child, like this:

    .hide {display: none;}
    div:not(.hide){
      color: red;
    }
    div:not(.hide) ~ div:not(.hide){
        color: black; /*reset everything to normal*/
    }
    

    But there is no way select last visible child with css. For this you need use javascript

提交回复
热议问题