CSS 悬停图像背景时遇到问题
我在网站上的导航部分遇到一些麻烦,该导航部分是列表中的文本...例如:
<div class="nav_wrapper">
<ul class="nav">
<li><a href="index.php">HOME</a></li>
<li><a href="about.php">ABOUT US</a></li>
<li><a href="services.php">SERVICES</a></li>
<li class="last"><a href="contact_us.php">CONTACT US</a></li>
</ul>
</div>
现在我想做的是悬停时显示图像背景;然而,当它这样做时,图像不会完全显示......它只围绕文本本身;这是有道理的,因为我将背景应用于 a 标签。
我尝试过设置宽度和宽度通过CSS设置a标签的高度,但它不起作用。
所以我的问题是如何让它在悬停时显示整个图像?
我当前的CSS如下:
#header .nav_wrapper {
float: left;
width: 597px;
margin: 30px 0 0 50px;
}
#header .nav_wrapper .nav {
list-style-type: none;
list-style-image: none;
}
#header .nav_wrapper li {
display: inline;
width: 72px;
height: 23px;
font-family: "Zurich Cn BT", Tahoma;
font-size: 12px;
margin-right: 15px;
}
ul.nav li a, ul.nav li a:visited, ul.nav li a:focus {
color: #764422;
text-decoration: none;
}
ul.nav li a:hover, ul.nav li a:active {
color: #fff;
text-decoration: none;
background-image: url(../images/nav-bg.png);
}
#header .nav .last {
width: 87px;
margin-right: 0;
}
I am having some trouble with a nav section on a site which is TEXT within a list... such as:
<div class="nav_wrapper">
<ul class="nav">
<li><a href="index.php">HOME</a></li>
<li><a href="about.php">ABOUT US</a></li>
<li><a href="services.php">SERVICES</a></li>
<li class="last"><a href="contact_us.php">CONTACT US</a></li>
</ul>
</div>
Now what I am trying to do is on hover have it display an image background; however when it does this the image doesn't display completely... it only surrounds the text itself; which makes sense as I am applying the background to the a tag.
I have tried setting a width & height to the a tag via css but it doesn't work.
So my question is how do I get it to display the whole image when they hover?
My current css is below:
#header .nav_wrapper {
float: left;
width: 597px;
margin: 30px 0 0 50px;
}
#header .nav_wrapper .nav {
list-style-type: none;
list-style-image: none;
}
#header .nav_wrapper li {
display: inline;
width: 72px;
height: 23px;
font-family: "Zurich Cn BT", Tahoma;
font-size: 12px;
margin-right: 15px;
}
ul.nav li a, ul.nav li a:visited, ul.nav li a:focus {
color: #764422;
text-decoration: none;
}
ul.nav li a:hover, ul.nav li a:active {
color: #fff;
text-decoration: none;
background-image: url(../images/nav-bg.png);
}
#header .nav .last {
width: 87px;
margin-right: 0;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
添加这个CSS
Add this CSS
链接需要是
display: block;
以便能够获取高度和宽度以使块级链接仍然并排显示,您应该浮动
li
项目或使它们display: inline-block;
例如,使用 float 表示
li
并使用一些颜色进行可视化the
<a>
links need bedisplay: block;
in order to be able to take height and widthto make the block level links still display side by side you should float the
li
items or make themdisplay: inline-block;
e.g. using float for the
li
's and some colors for visualisation