活动元素的 CSS 样式修复
首先,我是 CSS 新手,似乎不了解类如何与 id 交互,这就是为什么我无法使用以下菜单。
<div id="navmenu">
<ul>
<li><a href="#">Home</a></li>
<li><a href="index.php?=1">Menu2</a></li>
<li><a href="index.php?=2">Menu3</a></li>
</ul>
</div>
这是我的 CSS:
#navmenu ul {
margin: 0;
padding: 0;
list-style-type: none;
list-style-image: none;
}
#navmenu li {
width:114px;
text-align:center;
float:left;
}
#navmenu ul li a {
text-decoration:none;
color: white;
background: #CE140B;
}
#navmenu a {
padding-top:4px;
padding-bottom:4px;
display:block;
width:100%;
}
#navmenu ul li a:hover {
color: #CE140B;
background: white;
}
当鼠标悬停在菜单项上时,它会更改背景和前景色。
现在我想为此添加一个活动类,以便当我位于主页上时,主页菜单项看起来与悬停时相同。下面的代码不起作用。
我尝试将菜单更改为:
<li><a class="active" href="#">Home</a></li>
并且
<li class="active"><a href="#">Home</a></li>
将我的 CSS 更改为:
#navmenu ul li a:hover a:active {
color: #CE140B;
background: white;
}
并且
#navmenu ul li a:hover li:active {
color: #CE140B;
background: white;
}
两者都不起作用。感谢您帮助使其正常工作。
First of I am new to CSS and don't seem to understand how classes interact with id's, thats why I can not get the following menu to work.
<div id="navmenu">
<ul>
<li><a href="#">Home</a></li>
<li><a href="index.php?=1">Menu2</a></li>
<li><a href="index.php?=2">Menu3</a></li>
</ul>
</div>
This is my CSS:
#navmenu ul {
margin: 0;
padding: 0;
list-style-type: none;
list-style-image: none;
}
#navmenu li {
width:114px;
text-align:center;
float:left;
}
#navmenu ul li a {
text-decoration:none;
color: white;
background: #CE140B;
}
#navmenu a {
padding-top:4px;
padding-bottom:4px;
display:block;
width:100%;
}
#navmenu ul li a:hover {
color: #CE140B;
background: white;
}
This changes background and foreground color when the mouse is hovered over a menu item.
Now i wanted to add an active class to this, so that when I am on the Home page, the Home menu item looks the same as when it is hovered. The following code does not work.
I have tried changing the menu to this:
<li><a class="active" href="#">Home</a></li>
and also
<li class="active"><a href="#">Home</a></li>
and my CSS to:
#navmenu ul li a:hover a:active {
color: #CE140B;
background: white;
}
and
#navmenu ul li a:hover li:active {
color: #CE140B;
background: white;
}
Neither works. Thanks for your help on getting this to work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要么
或者
应该工作
Either
Or
Should work