【问题标题】:IE and :first-of-typeIE 和 :first-of-type
【发布时间】:2011-08-04 14:58:52
【问题描述】:

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

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 标记。我怎样才能解决这个问题,这样用户就不会只看到第一个斜线?

【问题讨论】:

    标签: css internet-explorer css-selectors


    【解决方案1】:
    li:first-child:before {
        content: '';
    }
    

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

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

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

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

    【讨论】:

    • +1 ... 因为:first-child 是CSS2 的一部分,而:first-of-type:last-child 是CSS3 的一部分。
    • 这么快,这么简单……我在网上找不到;)非常感谢
    • @smogg:现在不能上网了
    • @Tomalak 你指的是什么?我做了很多忍者编辑,现在我不确定:P
    • @alex:你的第二段文字。 :) [虽然 Boltclock 指出这确实是 CSS 的错。]
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多