css - IE 和 :first-of-type

标签 css internet-explorer css-selectors

我是初学者,所以如果你知道其他解决方案,请告诉我 ;) 我想让我网站上的菜单看起来像这样:

link / link / link / link / link

菜单在里面,所以这是我做的:

li:before {
    content: "/";
}

li:first-of-type {
    color: #FFF; /* I've made first "/" same color as background, so we don't see it */
}

有一些填充标签,所以看起来不错,但我想让它更容易阅读。

在大多数浏览器中它看起来不错,但当然旧的 Internet Explorer 不支持 :first-of-type 标签。我怎样才能解决这个问题,让用户不会只看到第一个斜杠?

最佳答案

li:first-child:before {
    content: '';
}

IE7及更高版本支持:first-child伪类。

请注意,IE7 支持 :first-child ( with some caveats ),但直到 IE9 才支持它的 friend :last-child

此外,要隐藏使用 content 属性添加的内容,请不要更改颜色以匹配背景颜色,因为这就是我所说的丑陋的 hack

相反,将其content 设置为空字符串,如上例所示。

关于css - IE 和 :first-of-type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5648142/

相关文章:

html - 为什么这个 Twitter 关注按钮不会下移?

Javascript:Cookie、选择框和 'document.getElementById' 在 Internet Explorer 中不起作用

asp.net - 格式验证摘要

javascript - 取消移动 IE 11 上事件的滚动

java - 单击部分标记内的元素

javascript - 在 CSS 中将 Div 宽度设置为 100% 打破了我脚本的宽度

jquery - 我不能使用 jquery 拖动可竞争的 div

jquery - 动态创建的 DOM 元素不增加 div 大小

css - 选择父元素中 3 的倍数的元素

selenium - Selenium 的 cssSelector 与 XPath