css - 应用 * :first-child +html in same CSS file with different attributes

标签 css

我有一个通用的 CSS 文件,有两个页面引用了它。

引用此通用 CSS 的页面需要以下 CSS,

*:first-child + html .rich-tabpanel {
   margin-left:-13px;        // Note : Its 13px here
}

引用此通用 CSS 的其他页面需要以下 CSS,

*:first-child + html .rich-tabpanel {
   margin-left: 0px;         //Note : Its 0px here 
}

HTML代码如下,

<table class="rich-tabpanel">

我只在 IE7 中遇到这个问题,它没有使用下面的代码(我不知道为什么),

.ie7 .rich-tabpanel {
   margin-left: 13px; //OR 0px depending on the page
}

所以,我删除了上面的代码,只使用了 *:first-child + html .rich-tabpanel 代码

如何在同一个通用 CSS 文件中为 rich-tabpanel 属性设置两个不同的 margin-left 属性?

最佳答案

从那一刻起 *:first-child +html .rich-tabpanel 是一个 hack,它是 specificity未知。 .ie7 .rich-tabpanel 具有特殊性 0020,因此黑客可能具有高于它的特殊性。将选择器 .ie7 .rich-tabpanel 更改为 html .ie7 .rich-tabpanel,这会更改特性,然后应用规则。我不保证这是一个特殊性问题,但在任何情况下更改选择器都是可行的。

演示: http://jsfiddle.net/xWX2R/1/

无论如何,我建议你使用conditional comments比 Internet Explorer 的黑客攻击。

关于css - 应用 * :first-child +html in same CSS file with different attributes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14120559/

相关文章:

jquery - 对图像的盲目影响

css - CSS 中的 [x* ="y"] 和 [x^ ="y"] 是什么意思?

html - CSS - 将位置从固定更改为允许滚动

javascript - 在开发过程中编辑 .js 和 .css 文件并避免缓存的最佳做法是什么?

html - 我如何通过将它变成一行代码来最小化 HTML 代码?

css - 调整浏览器窗口大小会影响 CSS 布局

html - 每行清算

javascript - 可折叠菜单不会在窗口调整大小时保持关闭状态

javascript - Bootstrap 导航栏中的链接

html - DIV 卡在页面左侧