gpt4 book ai didi

html - 将图像添加到导航栏链接

转载 作者:行者123 更新时间:2023-11-28 06:00:36 25 4
gpt4 key购买 nike

我想将 PNG 图像添加到我的导航栏。我找不到要添加到我的背景图像中的正确位置:并且它看起来是正确的。图像不以文本为中心,我需要它。谢谢

@charset "utf-8";

/* CSS Document */

body {
text-align: center
}
#navbar {
position: relative;
top: 15px;
padding: 0;
display: inline-block;
background-repeat: repeat-x;
border-radius: 15px;
}
#navbar li {
list-style: none;
float: left;
position: relative;
height: 50px;
line-height: 50px;
background-image: url(images/NAV.png);
}
#navbar li a {
display: block;
padding: 3px 30px;
text-transform: uppercase;
text-decoration: none;
color: #999;
font-weight: bold;
}
#navbar li a:hover {
color: #000;
}
#navbar li ul {
display: none;
position: absolute;
left: 0;
width: 100%;
margin: 0;
padding: 0;
text-align: center;
margin-left: -100px;
}
#navbar li ul table {
margin-top: -6px;
width: 350px;
background-image: url(images/NAV.png);
background-repeat: repeat-x;
border-radius: 15px;
}
#navbar li ul table tr {
height: 25px;
}
#navbar li:hover ul {
display: block;
}
#navbar li:hover li {
float: center;
}
#navbar li:hover li a {
color: inherit;
}
#navbar li li a:hover {
color: inherit;
}
#bottomnav {
position: fixed;
z-index: 100;
bottom: 15px;
left: 0;
width: 100%;
}
<body>
<header>
<img src="../images/logo.jpg" width="800" height="225" alt="This is our logo." />
</header>
<ul id="navbar">
<li><a href="../index.html">Home</a>
</li>
<li><a href="../services.html">Services</a>
<ul>
<table align="center">
<tr>
<td><a href="../spraying.html">Spraying</a>
</td>
<td><a href="../combine.html">Combining</a>
</td>
</tr>
<tr>
<td><a href="../planting.html">Planting</a>
</td>
<td><a href="../drilling.html">Drilling</a>
</td>
</tr>
<tr>
<td><a href="../strip_tillage.html">Strip Tillage</a>
</td>
<td><a href="../tillage.html">Tillage</a>
</td>
</tr>
</table>
</ul>
</li>
<li><a href="#">Packages</a>
</li>
<li><a href="#">About Us</a>
</li>
<li><a href="#">Contact Us</a>
</li>
</ul>
<div id="bottomnav">
Copyright 2016 Cole Rohr &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Site Map
</div>
</body>

enter image description here

最佳答案

我想你想要这样的东西:

#navbar li ul table {
margin-top: -6px;
width: 350px;
background-image: url('http://i.stack.imgur.com/RuH5Q.png');
background-repeat: no-repeat;
background-size: 100% 100%;
border-radius: 15px;
}

#navbar li {
list-style: none;
float: left;
position: relative;
height: 50px;
line-height: 50px;
background-image: url('http://i.stack.imgur.com/RuH5Q.png');
background-repeat: no-repeat;
background-size: 100% 100%;
}

Fiddle

或者像这样,为下拉菜单中 table 元素的每个 td 保留背景:

#navbar li ul table td {
background-image: url('http://i.stack.imgur.com/RuH5Q.png');
background-repeat: no-repeat;
background-size: 100% 100%;
}

Fiddle

关于html - 将图像添加到导航栏链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36779477/

25 4 0