我需要为 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最高会赢。如果您在两个样式表中提供相同的选择器,最新的将获胜。否则,从我上面链接的文章:
- Specificity determines, which CSS rule is applied by the browsers.
- Specificity is usually the reason why your CSS-rules don’t apply to some elements, although you think they should.
- Every selector has its place in the specificity hierarchy.
- If two selectors apply to the same element, the one with higher specificity wins.
- There are four distinct categories which define the specificity level of a given selector: inline styles, IDs, classes+attributes and elements.
- You can understand specificity if you love Star Wars: CSS Specificity Wars.
- You can understand specificity if you love poker: CSS Specificity for Poker Players
- When selectors have an equal specificity value, the latest rule is the one that counts.
- When selectors have an unequal specificity value, the more specific rule is the one that counts.
- Rules with more specific selectors have a greater specificity.
- The last rule defined overrides any previous, conflicting rules.
- The embedded style sheet has a greater specificity than other rules.
- ID selectors have a higher specificity than attribute selectors.
- You should always try to use IDs to increase the specificity.
- A class selector beats any number of element selectors.
- The universal selector and inherited selectors have a specificity of 0, 0, 0, 0.
- You can calculate CSS specificity with CSS Specificity Calculator.
关于html - 将使用哪个样式表? (IE条件语句),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/762906/