【问题标题】:Replace html css style with condition from css file用 css 文件中的条件替换 html css 样式
【发布时间】:2012-03-04 01:55:43
【问题描述】:

我有这个问题,我不知道如何解决它。在我的项目中,许多 html 文件都为 div 定义了宽度样式,例如:

<div style="width:200px" id="boom">/*****/</div>

如果我在 css 文件中添加如下条件:

`div#boom{width:auto !important;}`

被忽略,因为样式是在 html 中为该 div 定义的,并且据我所知,html 条件击败 css 条件。 怎么可能解决这个问题?我不想编辑所有的 html 页面,因为我会花很长时间。

【问题讨论】:

    标签: html css conditional-statements


    【解决方案1】:

    你做错了什么。因为!important 将样式设置为最高优先级,所以它始终使用width: auto; 而不是内联CSS。

    一个有效的例子:http://tinkerbin.com/wzrFiyaq
    还有一个教程:http://css-tricks.com/override-inline-styles-with-css/

    【讨论】:

    • @Jared 你可以在没有 [style] 属性选择器的情况下做到这一点。
    【解决方案2】:
    div[style] {
       width:auto !important;
       }​
    

    【讨论】:

    • 为什么右大括号后面是auto这个词?
    • 是的,那个链接没有提到auto,它是在谈论!important...
    猜你喜欢
    • 2021-05-01
    • 2013-08-04
    • 1970-01-01
    • 1970-01-01
    • 2021-04-17
    • 1970-01-01
    • 2015-11-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多