将图像添加到导航栏链接

时间:2016-04-21 20:10:06

标签: html css

我想在我的导航栏中添加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>
&#13;
&#13;
&#13;

enter image description here

1 个答案:

答案 0 :(得分:0)

我想你想要这样的东西:

#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

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

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

Fiddle