Understanding CSS selectors

前端 未结 5 913
一个人的身影
一个人的身影 2020-12-16 07:58

Why is it that the below makes the text red?

#stories li a {color:red}
.default li.expand a {color:green}
li.expand a {color:blue}

         


        
5条回答
  •  失恋的感觉
    2020-12-16 08:06

    Selectors work based on how specific a rule is. An id uniquely identifies a specific element, so it is as specific as you can get.

    Take this example:

     
    • this is the end
    • this is the end
    • this is the end
    • this is the end
    • this is the end
    • this is the end

    How would you target just the #stories list if the selectors didn't work that way?

提交回复
热议问题