【问题标题】:CSS Global Class Issue with Child孩子的 CSS 全局类问题
【发布时间】:2023-04-07 00:07:01
【问题描述】:

我有一个 html 的全局类

<div class="wrapper">

<div class="content"></div>

</div>

CSS 是

.div { width:auto; display:block }


.content {  width:100px;  height:50px; }

在 .content div 上,我不需要“display:block”类。但它适用于运行时。 我给了显示:继承;但它不起作用。有没有其他方法可以去除显示样式?

【问题讨论】:

  • .div 仅适用于具有 div 类的元素,您的意思是使用div { }吗?
  • 除了显式覆盖它们之外,没有其他方法可以删除继承的样式
  • 你想说“display:block;”属性在运行时应用到您的 div 中?如果它在运行时应用,这意味着它可能是目标 div 上的内联属性,在这种情况下,您可以在运行时通过应用任何其他值进行显示来删除它。或者如果你想使用 CSS,那么你应该使用“!important”。这样它就可以忽略内联css

标签: javascript jquery html css


【解决方案1】:
.div { width:auto; display:block }

这可能不起作用....对于上面提供的 html cos 没有名为类的 div

你能做的是

.content {  width:100px;  height:50px; display:inline}

【讨论】:

    【解决方案2】:
    .content {  width:100px;  height:50px; display: inline; }
    

    或其他显示属性

    【讨论】:

      【解决方案3】:

      你可以这样做:

      .content {  width:100px;  height:50px; display:inline }
      //or display:none or whatever your standard default is
      

      inline是默认值,见MDN Ref

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-09-02
        • 1970-01-01
        • 1970-01-01
        • 2011-07-14
        • 1970-01-01
        • 1970-01-01
        • 2017-03-30
        • 1970-01-01
        相关资源
        最近更新 更多