仅当在同一 div 上具有特定类时,如何使用 css 特定 id 进行选择?

Noo*_*AFK 0 html css css-selectors

所以这是情况,当导航在底部时,拳头代码显示类......

<div id="navigation" class="attached-to-bottom">
 <ul>
  <li></li>
  <li></li>
  <li></li>
 </ul>
</div>
Run Code Online (Sandbox Code Playgroud)

当我向下滚动(使用 jquery 等)后,当我的导航保持在顶部时显示,但是当我触发类“附加到顶部”时,我需要将导航 ID 高度更改为不同)我可以只使用 CSS 还是?

 <div id="navigation" class="attached-to-top">
     <ul>
      <li></li>
      <li></li>
      <li></li>
     </ul>
    </div>
Run Code Online (Sandbox Code Playgroud)

Mic*_*ael 5

只是不要在它们之间使用空格。

#navigation.attached-to-top { height: 100px; }
Run Code Online (Sandbox Code Playgroud)

有关CSS 选择器的更多信息

  • 在 CSS 3 中,它被称为 [“简单选择器的序列”](http://www.w3.org/TR/2009/PR-css3-selectors-20091215/#sequence)。 (3认同)