Is an attribute selector for the ID attribute less specific than an ID selector?

前端 未结 2 990
眼角桃花
眼角桃花 2020-12-11 21:41

What do I need to do to give the [id^=value] selector the same specificity as a regular ID, and why isn\'t it equal or greater already? (considering that I

2条回答
  •  忘掉有多难
    2020-12-11 22:26

    You may consider the not() selector in order to append a random ID and you will then have a higher or the same specifity since the specifity of not() is equal to the specifity of the selector inside it:

    html body div[id^="blue"]:not(#randomID) {
      background-color: blue
    }
    
    #blue4 {
      background-color: red
    }
    
    div {
      height: 50px;
      width: 50px
    }

提交回复
热议问题