如何指定要使用的特定 CSS 类?

Cod*_*ven 2 html css sass

我有一个 html 块,如下所示:

\n
<div id=\xe2\x80\x9cstage\xe2\x80\x9d>\n     <div class=\xe2\x80\x9cticker universal\xe2\x80\x9d>\n    \xe2\x80\xa6\n     </div>\n</div>\n
Run Code Online (Sandbox Code Playgroud)\n

类的 css 看起来像这样:

\n
#stage {\n    position: absolute\n}\n\n.ticker.universal\xc2\xa0{ \xe2\x80\xa8        \n    position: relative;\n}\n
Run Code Online (Sandbox Code Playgroud)\n

我遇到的问题是.ticker.universal位置属性被#stage位置属性覆盖。当我查看浏览器控制台中的元素时, 的位置.ticker.universal实际上被删除了。

\n

我尝试添加!important.ticker.universal位置,它有效,但我试图避免使用!important.

\n

请问还有什么方法可以解决这个问题吗?

\n

小智 5

请访问以下网址,以更好地解决您的问题。

https://developer.mozilla.org/en-US/docs/Web/CSS/position

https://css-tricks.com/almanac/properties/p/position/

      #stage {  
         position: relative;
         
          /*Apply your css code */
         height: 300px;
         width: 600px;
         background-color: beige;
      }

      #stage .ticker-universal {
         position: absolute;
         
          /*Apply your css code */
         height: 50px;
         width: 100px;
         background-color: coral;
         top: 0;
         left: 0;

      }
Run Code Online (Sandbox Code Playgroud)
<div id="stage">
  <div class="ticker-universal">

  </div>
</div>
Run Code Online (Sandbox Code Playgroud)