使用ID和CLASS激活的CSS

KJS*_*KJS 2 css css-selectors

我如何使用这个CSS编码,class="active"以便下面显示背景?使用不同的颜色.active,可以这么说(不是:hover).

<a href="[url]" id="curs_section" class="active">kids</a>
Run Code Online (Sandbox Code Playgroud)

我的尝试:

a#curs_section .active  {
    background-color: #66a7eb; 
    color: #333; 
}
Run Code Online (Sandbox Code Playgroud)

PSL*_*PSL 6

你之前不应该有空间,.active因为它是锚本身的类.a#curs_section .active表示具有类active的后代的元素a#curs_section,因此您的样式未被应用.

a#curs_section.active  {
    background-color: #66a7eb; 
    color: #333; 
}
Run Code Online (Sandbox Code Playgroud)


Mar*_*c B 5

取出空间:

a#curs_section .active  {
              ^---
Run Code Online (Sandbox Code Playgroud)

对于空格,它是一个<a>带有curs_section ID 的元素,后跟一些带有类的OTHER元素.active.

没有空间:

a#curs_section.active  {
Run Code Online (Sandbox Code Playgroud)

它是一个<a>id curs_section和.active类.