【问题标题】:Remove the css of a child class by a parent class父类删除子类的css
【发布时间】:2014-10-25 01:16:15
【问题描述】:

我有

HTML:

<div class="parent">
<div class="child">
</div>
</div>

和

<div class="child">
</div>

CSS:

.child{  width:2px;height:3px };
.parent .child{color:blue};

当我在 css 中包含父类时,我想删除子类的样式,即如果我使用 .parent .child,则子类不应有宽度和高度样式,即如果与子类一起使用,则应删除子类的样式父母。我该怎么做?

【问题讨论】:

    标签: css


    【解决方案1】:

    以下代码 sn-p 将起作用。当子节点在父节点内时,将其宽度和高度设置为元素默认值,即auto。

    .parent .child {
        color: blue;
        width: auto;
        height: auto;
    }
    

    【讨论】:

    • 如果您只想直接在 .parent 下选择 .child 类,请使用 .parent &gt; .child {}
    猜你喜欢
    • 2021-12-03
    • 2017-06-03
    • 2020-04-27
    • 1970-01-01
    • 2019-12-28
    • 2021-03-28
    • 2020-07-16
    • 2016-09-06
    • 2016-08-11
    相关资源
    最近更新 更多