html - 取消悬停在导航栏中的一个按钮的效果

标签 html css navigation html-lists

我有一个黑色背景和白色文本的导航栏。将鼠标悬停在上方时,文本会变为红色。但是,当用户在选择页面上时,特定背景将变为红色。但是,将鼠标悬停在上方会将文本更改为红色。我想要它,以便当用户在主页上并将鼠标悬停在主页按钮上时,文本不会变为红色。

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>TL Custom Printing</title>

<link rel="stylesheet" type="text/css" href="stylesheet.css" />


</head>

<body>

<div id="topbar">
</div>

<div id="navbar">
    <div id="navbtn">
        <ul>
            <li><a href="index.php" style="background-color:#F00;">Home</a></li>
            <li><a href="custom.php" >Custom Printing</a></li>
            <li><a href="store.php">Products</a></li>
            <li><a href="gallery.php">Gallery</a></li>
            <li><a href="about.asp">About</a></li>
            <li><a href="contact.asp">Contact Us</a></li>
        </ul>
    </div>
</div>

<div id="logo">
    <img src="testlogo.png" alt="logo">
</div>



</body>

</html>

CSS:

#navbtn {
    width:100%;
    Margin:20px;
    white-space: nowrap;
    text-align:center
}

ul {
    width:100%;
    list-style:none;
    margin:0;
    padding:0;
    display: inline-block;
    padding-top: 2.25em;
}

li {
    width: 140px;
    display: inline-block; 
}

a {
    text-align:center;
    font-size: 1.25em;
    padding:8px 0;
    display:block;
    width:100%;
    text-decoration:none;
    color:#FFF;
    border-top-left-radius:8px;
    border-top-right-radius:8px;

}

a:hover {
    color:#F00;
    background-color:#000;
}

最佳答案

您可以使用事件类轻松解决此问题:JSFiddle

<li><a href="index.php" class="active">Home</a></li>

a.active {
    background-color:#F00;
}
a.active:hover {
    color: #fff;
}

我还将您的事件选项卡背景颜色添加到 .active 类中,删除了您的内联样式

关于html - 取消悬停在导航栏中的一个按钮的效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24738848/

相关文章:

javascript - 更改 CSS3 变换值?

javascript - 每次单击 div 时更改正文背景颜色

html - 用于动画的 CSS 属性不能用于 chrome 中的悬停

html - 打破 h2 标题而不是移动图像

jquery - 这个移动的火箭是否使用 CSS3(动画)?

navigation - vim 中的自定义 block 限制器

php - 在没有 .htaccess 的情况下,我有哪些替代方案来开发网站导航?

javascript - 如何访问 `<div>` 标签内的 `<p>` 标签?

html - CSS 类的媒体查询

javascript - 为什么这个菜单在 IE 中会出现问题?紧急求救