忽略CSS标签

时间:2012-03-12 15:07:29

标签: css

我想知道是否有办法忽略标签:

<!-- I can add code here -->

<!-- I cannot edit the following start -->
<style>
     div, td {
     color: #555555;
     font-size: 10pt;
     text-align: left; 
     }
</div>
<!-- I cannot edit the following end -->

<div id="myapp" style="color:red"><div>Test</div></div>

我想知道是否有任何东西我可以添加以跳过这些通用的div / td样式。例如#myapp div { font-color: inherit; }

2 个答案:

答案 0 :(得分:2)

没有简单的CSS方法可以忽略以后的CSS规则。

最可靠的选择是使用JavaScript删除标记。

示例:在<style>元素后删除第一个 <script>标记:

<script id="unique-id-script">
setTimeout(function() {
    var removeTheNthStyleElement = 1, found = 0,
        script = document.getElementById('unique-id-script'), elem = script;
    while (elem = elem.nextSibling) {
        if (elem.nodeName.toUpperCase() === 'STYLE') {
            if (++found === removeTheNthStyleElement) {
                // Remove style element => disable styles
                elem.parentNode.removeChild(elem);
                // Remove temporary script element
                script.parentNode.removeChild(script);
                break;
            }
        }
    }
}, 4);
</script>
... anything but a style element...
<style>
/* I want to prevent these rules from being used */
</style>

答案 1 :(得分:0)

这将继承红色

#myapp div{
  color: inherit;
}