如何将CSS应用于带有母版页的导航栏?

时间:2013-05-15 09:15:46

标签: c# html5 css3 navigation

我正在开发一个项目,但是仅将CSS应用于导航栏时遇到问题。我的项目包含

  1. 母版页
  2. home.aspx
  3. gallery.aspx
  4. 当我将menu.css文件应用于master.page上的导航栏时,它会影响其余的表格以及其他内容页面(home.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;
    }
    

    请帮帮我。

1 个答案:

答案 0 :(得分:1)

要将CSS应用于一个元素,请使用id,例如。然后在CSS中:

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

其他元素(不带id == nav)不会受到影响。

实施例: http://jsfiddle.net/igos/tJWq6/