html - 导航列表 a :hover

标签 html css

我正在创建一个网站,目前它的导航栏位于“ build 中”。我想要它,所以当我将鼠标悬停在它上面时,整个 nav ul li 背景都会改变颜色,而不仅仅是文本后面的背景。我有这个:

<html>
<head>
    <link href='http://fonts.googleapis.com/css?family=Noto+Sans' rel='stylesheet' type='text/css'>
    <title>Landstown High School and Technology Academy - Home</title>
    <link rel="stylesheet" type="text/css" href="main.css">
</head>
<body>
    <header>
        <nav>
            <ul>
                <li class="active"><a href="#">Home</a></li>
                <li><a href="#">Contact Us</a></li>
                <li><a href="#">Sharepoint</a></li>
                <li><a href="#">Employees</a></li>
            </ul>
        </nav>
    </header>
    <section class="body">
</body>
</html>

这是 CSS:

body
{
margin: 0;
padding: 0;
font-family: 'Noto Sans', sans-serif;
background: #F8F8F8

}

/****HEADER STUFF****/

header
{
position: fixed;
height: 10%;
width: 200%;
background: #F8F8F8;
box-shadow: -10px 0px 10px #000;
}

nav
{
margin-right: 7%;
margin-left: 7%;
height: 40px;
}

nav a:hover
{
background: #00248F;
}

nav ul
{
width: 40%;
background: #0033CC;
line-height: 40px;
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px; 
}

nav ul li
{
display: inline;
padding: 8%;
}

nav ul li a:hover
{
text-decoration: none;
}

nav ul li a
{
color: #F8F8F8;
text-decoration: none;
}

nav ul li a:visited
{
text-decoration: none;
}

我该怎么做?

最佳答案

试试这个:http://jsfiddle.net/3BBe2/2/ .我已经修改了你的代码。

新的 CSS:

    body
{
margin: 0;
padding: 0;
font-family: 'Noto Sans', sans-serif;
background: #F8F8F8

}

/****HEADER STUFF****/

header
{
position: fixed;
height: 10%;
width: 200%;
background: #F8F8F8;
box-shadow: -10px 0px 10px #000;
}

nav
{
margin-right: 7%;
margin-left: 7%;
height: 40px;
}

nav ul a{
    padding:3px 3px;
}

/* nav li a:hover
{
    background: #00248F;
} */

nav ul
{
width: 60%;
background: #0033CC;
line-height: 40px;
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px; 
}

nav ul li
{
display: inline;
padding: 8%;
padding:5px 5px;
    padding:10px 12px 10px;
}

nav ul li:hover
{
    background: #00248F;

}

 nav ul li a
{
color: #F8F8F8;
text-decoration: none;

}

nav ul li a:visited
{
text-decoration: none;
}

关于html - 导航列表 a :hover,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16375495/

相关文章:

javascript - 不同 iOS 设备(Cordova/phonegap)的 safari 中的不同主体

javascript - 根据 URL 中的哈希标签执行操作

html - 如何限制评论框中的每个 <li> 元素?

html - "navbar-header"类在 Bootstrap 中做什么?

html - toastr (ngx-toastr)顶部居中对齐没有顶部边距

javascript - 无法在我的 js 函数中使用 parseInt 或 Number 从 HTML 获取数值

html - CSS Transition,为什么折叠父 div 不会同时折叠子元素?

javascript - 无法在 &lt;script&gt; 标签内回显 PHP 变量?

html - HTML 属性需要引号吗?

java - Action 标签在 Struts 2 中不执行