我的导航栏由黑色列表项组成。当我将鼠标悬停在它们上方时,链接周围会出现一个深灰色框,文字从黑色变为白色(这就是我想要实现的目标)。通过使用标签使链接处于活动状态后,文本将变为超链接。我尝试了文本修饰:无和改变html中文本的颜色,但两种方式都没有成功。如何制作列表项链接,但是将它们显示为文本并保持所需的悬停效果,文本从黑色变为白色?
这是我的HTML:
<div style="position:absolute; left:170px; font-family: 'Raleway', serif;;" class="navbar">
<ul><li><a href="Homepage.php">HOME</a></li>
<li><a href="commercial.php">COMMERCIAL</a></li>
<li>
RESIDENTIAL
<ul>
<li><a href="remodels.php">REMODELS</a></li>
<li><a href="additions.php">ADDITIONS</a></li>
<li><a href="exteriors.php">EXTERIORS</a></li>
</ul>
</li>
<li><a href="sustainable.php">SUSTAINABLE</a></li>
<li><a href="family.php">FAMILY</a></li>
<li><a href="community.php">COMMUNITY</a></li>
<li><a href="contacts.php">CONTACT</a></li>
</ul>
</div>
这是CSS:
.navbar {
padding: 5px 50px 150px;
font-size: 14px;
text-align: center;
}
.navbar ul {
text-align: left;
display: inline;
margin: 0;
padding: 15px 4px 17px 0;
list-style: none;
}
.navbar ul li {
display: inline-block;
margin-right: -4px;
position: relative;
padding: 15px 20px;
background: #fff;
cursor: pointer;
-webkit-transition: all 0.2s;
-moz-transition: all 0.2s;
-ms-transition: all 0.2s;
-o-transition: all 0.2s;
transition: all 0.2s;
}
.navbar ul li:hover {
background: #555;
color: white;
}
.navbar ul li ul {
padding: 0;
position: absolute;
top: 48px;
left: 0;
width: 150px;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
display: none;
opacity: 0;
visibility: hidden;
-webkit-transiton: opacity 0.2s;
-moz-transition: opacity 0.2s;
-ms-transition: opacity 0.2s;
-o-transition: opacity 0.2s;
-transition: opacity 0.2s;
}
.navbar ul li ul li {
background: #555;
display: block;
color: #fff;
text-shadow: 0 -1px 0 #000;
}
.navbar ul li ul li:hover { background: #666; }
.navbar ul li:hover ul {
display: block;
opacity: 0.9;
visibility: visible;
}
答案 0 :(得分:1)
只需将以下内容添加到您的css:
.navbar ul li a {
text-decoration: none;
color: black;
}
.navbar ul li:hover a {
color: white;
}