CSS!重要的不工作 [英] CSS !important not working

查看:118
本文介绍了CSS!重要的不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,由于某种原因,!important 限定符不工作。

I have the following code and for some reason the !important qualifier isn't working.

<div style="font-family : calibri; font-size: 20pt !important;">
  <ul>
    <li>
      <span style="font-size: 11px;">
        <span style="font-size: 11px;">
          Honey Glazed Applewood Smoked Spiral Ham 
        </span>
        <span style="font-size: 11px;">
          Served with Dijon Honey Mustard and Turkey Roulade
        </span>
      </span>
    </li>
  </ul>
</div>

为网站格式生成span标记。我添加了div标签将输出更改为PDF格式,而不是写一个看似过于复杂的find和replace函数。因为这个黑客是针对特定区域的代码,我不能改变CSS表。

The span tags are generated for website formatting. I was adding the div tag to change the output to PDF format instead of writing a seemingly overcomplicated find and replace function. Since this hack is for specific regions of code, I can't change the CSS sheet.

任何想法都不胜感激。

Any thoughts would be appreciated.

推荐答案

提供< div> 规则到您的CSS样式表(如果您不想更改样式表,则在< style> 标记中):

Give the <div> an id and then add this rule to your CSS stylesheet (or in a <style> tag if you don't want to change the style sheet):

#your_div_id span {
    font-family : calibri; font-size: 20pt !important;
}

!important CSS允许作者重写内联样式(因为它们通常比样式表样式具有更高的优先级)。它不会自动使!style 的样式覆盖所有其他内容。

!important in CSS allows the author to override inline styles (since they have a higher precedence than style sheet styles normally). It doesn't automatically make the style marked !important override everything else.

strong> W3C有关CSS选择器特定性的文档

< a href =http://jsfiddle.net/fkling/ZcXY4/> Felix的标记演示

这篇关于CSS!重要的不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆