CSS中是否可以有多个ID选择器

Joh*_*n T 0 html css css3

这是正确的,并且可以在所有浏览器中正常工作吗?

<div id="test">
  Some stuff
    <div id="anotherTest">
      More stuff
    </div>
  Even more stuff
</div>
Run Code Online (Sandbox Code Playgroud)

CSS ...

#test #anotherTest {
  color:red;
}
Run Code Online (Sandbox Code Playgroud)

只有“更多内容”为红色。

我知道我可以使用类,并且有几种不同的方法可以实现这一点,但是基本上我是在问通过几个ID选择带有CSS的元素吗?

谢谢。

Sun*_*ari 5

是的,这种方法是可行的

#test #anotherTest {
  color:red;
}
Run Code Online (Sandbox Code Playgroud)

它选择具有元件id anotherTest,其具有ancestorid test

阅读