IE和:首先是类型

smo*_*ogg 4 css internet-explorer css-selectors

我是初学者,所以如果你知道其他解决方案告诉我;)我想在我的网站上制作菜单如下:

link / link / link / link / link
Run Code Online (Sandbox Code Playgroud)

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

li:before {
    content: "/";
}

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

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

在大多数浏览器中它看起来很好,但当然旧的Internet Explorer不支持:first-of-type标签.我怎么能解决它,所以用户不会看到第一个斜杠?

ale*_*lex 15

li:first-child:before {
    content: '';
}
Run Code Online (Sandbox Code Playgroud)

:first-child伪类是由IE7及更高版本支持.

请注意,IE7支持:first-child(有一些警告),但直到IE9支持它的朋友:last-child.

此外,要隐藏添加了content属性的内容,请不要更改颜色以匹配背景颜色,因为这就是我称之为丑陋的黑客.

而是将其设置content为空字符串,如上例所示.

  • +1 ...因为`:first-child`是CSS2的一部分,而`:first-of-type`和`:last-child`是CSS3的一部分. (5认同)
  • @smogg:*现在关于互联网* (2认同)