html - #current css 帮助

标签 html css css-selectors

我似乎无法正常工作...我有几个菜单项需要全局设置中的不同背景项。

这是工作正常的全局设置...

#left #current a {background-image: url(../images/leftbuttonactive.png); color: #000;}

但是我需要将不同的背景图像应用到某些元素,这些元素是 2 行文本,因此是 .itemxxx。下面的每一行都是我测试过的,没有一个有效。

#left #current .item136 a,
.item136 #current a,
#current .item136 a,
#current .item136 > a,
#left #current .item136 a:link,
#left ul li.item136 li.active a:link,
#left #current .item136 a,
#left li.item136 #current a,
background-image: url(../images/leftbutton2lineactive.png);}

这适用于 :hover 或 :visited...

#left li.item136 a:hover

我已经尝试了很多变体(如您在代码 2 中所见),但没有成功。有什么建议吗?

最佳答案

如果 #current 也是一个 li 并且可能有类 item136:

#left .item136 a, #left #current.item136 a {
    background-image: url(../images/leftbutton2lineactive.png);
}

注意 #current.item136 之间没有空格;如果它同时具有 ID 和类,这将要求您的浏览器选择一个元素。您需要指定它,因为单独的 ID 选择器比单独的类选择器更具体,并且您的 ID 样式将覆盖类样式。

关于html - #current css 帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4821691/

相关文章:

Css:使用类将样式添加到最后一个元素(没有js)

html - 在 Ubuntu 上通过 NGINX 加载 html 页面时出现 500 内部服务器错误

javascript - JQuery:为什么ajax请求在beforeSend中的代码执行完成之前执行?

javascript - HTML5验证: field not required but,如果填写,必须匹配模式?

php - 如何在使用 PHP 从 HTML 创建的 DOC 文件中包含 CSS

html - 在每第 10 个 div 元素之后隐藏前 4 个 div

html - ASP.NET TABLE + 在一个可滚动的 DIV 中,+ 表格单元格位置 :Relative : ModalPopupExtender

javascript - 使覆盖文本的 div 仅对文本进行动画处理和着色

html - 菜单按钮不会移动

html - CSS 选择器不起作用?