如何将CSS应用到导航栏与母版页

本文关键字:导航 母版页 应用 CSS | 更新日期: 2023-09-27 18:13:53

我正在做一个项目,但是有只应用CSS到导航栏的问题。我的项目包含

  1. 主页
  2. home.aspx
  3. gallery.aspx

当我将menu.css文件应用到master.page上的导航栏时,它会影响其余的表以及其他内容页面(主页)。Aspx和gallery.aspx)的代码如下所示:

master.page

<body style="background-image: url('/WebSite5/bacground/Fruit-drinks-vector-pptbackgrounds.jpg')">
<form id="form1" runat="server">
<div>
  <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">        
    <table align="center" class="style1">
      <tr>
        <td style="text-align: center">
          <img alt="" class="style2" src="bacground/logo.png" />
        </td>
      </tr>
      <tr>
        <td>
          <uc1:menu ID="menu1" runat="server" />
        </td>
      </tr>
    </table>        
  </asp:ContentPlaceHolder>
</div>
<table class="style3">
  <tr>
    <td style="text-align: center">
      <asp:ContentPlaceHolder ID="ContentPlaceHolder3" runat="server">
      </asp:ContentPlaceHolder>
    </td>
  </tr>
</table>
</form>
</body>

menu.ascx

<table class="style1">
  <tr>
    <td>
      <ul id="nav">`enter code here`
        <li class="home" aria-orientation="horizontal"><a href="#">Home</a></li>
        <li class="Gallery"><a href="#">Gallery</a></li>
        <li class="events"><a href="#">Events</a></li>
        <li class="About US"><a href="#">About US</a></li>
        <li class="contact"><a href="#">Contact</a></li>
      </ul>
    </td>
  </tr>
</table>

menu.css

#ul li {
  list-style: none;
  height: 44px;
  float: left;
  padding: 10px 5px;
  width: 175px;
}
#ul li a {
  width: 146px;
  height: 40px;
  line-height: 53px;
  border-bottom: 4px solid #636393;
  padding:0px;
  color: #fff;
  font-size:18px;
  font-weight:lighter;
  text-align:center;
  text-decoration: none;
  display: block;
  -webkit-transition: .2s all linear;
  -moz-transition: .2s all linear;
  -o-transition: .2s all linear;
  transition: .2s all linear;
}
#li:nth-child(1) a {
  border-color: #636393;
}
#li:nth-child(2) a {
  border-color: #B5222D;
}
#li:nth-child(3) a {
  border-color: #D4953C;
}
#li:nth-child(4) a {
  border-color: #609491;
}
#li:nth-child(5) a {
  border-color: #87A248;
}
#li:nth-child(1) a:hover {
  border-bottom: 35px solid #636393;
  height: 9px;
}
#li:nth-child(2) a:hover {
  border-bottom: 35px solid #B5222D;
  height: 9px;
}
#li:nth-child(3) a:hover {
  border-bottom: 35px solid #D4953C;
  height: 9px;
}
#li:nth-child(4) a:hover {
  border-bottom: 35px solid #609491;
  height: 9px;
}
#li:nth-child(5) a:hover {
  border-bottom: 35px solid #87A248;
  height: 9px;
}

请帮帮我。

如何将CSS应用到导航栏与母版页

要在一个元素上应用CSS,使用id,例如:

#nav {
    color:yellow;
}
#nav li {
    font-size:19pt;
}

其他元素(id==nav除外)不受影响。

的例子:http://jsfiddle.net/igos/tJWq6/