html - 将使用哪个样式表? (IE条件语句)

标签 html css internet-explorer

我需要为 IE 使用不同的样式表,我想知道哪个样式表会控制。

例如,我将在 中使用此代码:

<link rel="stylesheet" type="text/css" href="styles/style.css" />
<!--[if IE]><link rel="stylesheet" type="text/css" href="styles/ie.css" /><![endif]-->

那么我是否需要在 IE 样式表中到处使用 !important?或者第二个样式表会被 IE 视为更重要吗?顺序重要吗?

最佳答案

无论哪种款式的specificity最高会赢。如果您在两个样式表中提供相同的选择器,最新的将获胜。否则,从我上面链接的文章:

  1. Specificity determines, which CSS rule is applied by the browsers.
  2. Specificity is usually the reason why your CSS-rules don’t apply to some elements, although you think they should.
  3. Every selector has its place in the specificity hierarchy.
  4. If two selectors apply to the same element, the one with higher specificity wins.
  5. There are four distinct categories which define the specificity level of a given selector: inline styles, IDs, classes+attributes and elements.
  6. You can understand specificity if you love Star Wars: CSS Specificity Wars.
  7. You can understand specificity if you love poker: CSS Specificity for Poker Players
  8. When selectors have an equal specificity value, the latest rule is the one that counts.
  9. When selectors have an unequal specificity value, the more specific rule is the one that counts.
  10. Rules with more specific selectors have a greater specificity.
  11. The last rule defined overrides any previous, conflicting rules.
  12. The embedded style sheet has a greater specificity than other rules.
  13. ID selectors have a higher specificity than attribute selectors.
  14. You should always try to use IDs to increase the specificity.
  15. A class selector beats any number of element selectors.
  16. The universal selector and inherited selectors have a specificity of 0, 0, 0, 0.
  17. You can calculate CSS specificity with CSS Specificity Calculator.

Here are the official docs on it .

关于html - 将使用哪个样式表? (IE条件语句),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/762906/

相关文章:

javascript - Highcharts X 轴对齐

javascript - 调试 AngularJS Internet Explorer 锁定

javascript - iframe 不工作。努力在 Iframe 中执行脚本标签

html - css 关键帧垂直旋转单词

javascript - 如何在 JavaScript 中避免使用 HTML

html - 悬停时带有动画 gif 的菜单

html - 如何显示 :focus color and outline in Safari?

javascript - 在 Javascript 中创建一个按钮

html - 在覆盖内部内容的伪元素之前

internet-explorer - 基本认证 : IE 11 Does Not Prompt for Credentials - Chrome and FF Do