2012-02-28 118 views
0

我正在構建一個asp.net mvc應用程序。我有我的主菜單中的頂級菜單結構。它似乎呈現不同的屏幕尺寸或不同的屏幕分辨率。這使菜單結構看起來很糟糕。我希望它在任何時候都一樣。 下面是我的母版頁HTML:菜單樣式,CSS,HTML。頂部菜單避免溢出

<body> 
<div class="page"> 

    <div id="header"> 
     <div id="badge" style="float:left; width:20%;"><img src="../../Content/Images/School_Badge.jpg" alt="badge"/></div> 

     <div id="title" style="width:80%;"> 
      <h1>School</h1> 
      <h2> 
      School Motto: Famba <br /> 
      English Meaning: Move Forward 
      </h2> 
     </div> 

     <br/><br/><br/><br/> 
     <div id="menucontainer"> 

      <ul id="menu">    
       <li><%: Html.ActionLink("About us", "Index", "Home")%></li> 
       <li><%: Html.ActionLink("Admissions", "Admissions", "Home")%></li> 
       <li><%: Html.ActionLink("Boarding", "Boarding", "Home")%></li> 
       <li><%: Html.ActionLink("Academic", "Academic", "Home")%></li> 
       <li><%: Html.ActionLink("Cultural", "Cultural", "Home")%></li> 
       <li><%: Html.ActionLink("Sport", "Sport", "Home")%></li> 
       <li><%: Html.ActionLink("Staff members", "Staff", "Home")%></li> 
       <li><%: Html.ActionLink("Contact us", "ContactUs", "Home")%></li> 
      </ul> 

     </div> 
    </div> 

    <div id="main"> 
     <asp:ContentPlaceHolder ID="MainContent" runat="server" /> 

     <div id="footer"> 
     P.O Box 507 School| Phone: +23232 39 265064 | Fax: +232332 39 266043 | 
     © Copyright Private School <%: DateTime.Now.Year %> <br /> <br /> 
     </div> 
    </div> 
</div> 

和與此相關的CSS如下:

.page 
{ 
    width: 72%; 
    margin-left: auto; 
    margin-right: auto; 
} 

#header 
{ 
    position: relative; 
    margin-bottom: 0px; 
    color: #000; 
    padding-top: 20px; 
} 

#header h1 
{ 
    font-weight: bold; 
    padding: 5px 0; 
    margin: 0; 
    color: #fff; 
    border: none; 
    line-height: 2em; 
    font-family: Arial, Helvetica, sans-serif; 
    font-size: 32px !important; 
} 

#header h2 
{ 
    font-weight: bold; 
    padding: 5px 0; 
    margin: 0; 
    color: #fff; 
    border: none; 
    line-height: 2em; 
    font-family: Arial, Helvetica, sans-serif; 
    font-size: 14px !important; 
} 

#main 
{ 
    position:relative; 
    padding: 30px 0px 15px 0px; 
    background-color: #fff; 
    margin-bottom: 30px; 
    _height: 1px; /* only IE6 applies CSS properties starting with an underscore */ 
} 

#menucontainer 
{ 
    margin-top:100px; 
} 

div#title 
{ 
    display:block; 
    float:left; 
    text-align:left; 
} 

ul#menu 
{ 
    border-bottom: 1px #5C87B2 solid; 
    padding: 0 0 2px; 
    position: relative; 
    margin: 0; 
    text-align:center; 
} 

ul#menu li 
{ 
    display: inline; 
    list-style: none; 
} 

ul#menu li#greeting 
{ 
    padding: 10px 20px; 
    font-weight: bold; 
    text-decoration: none; 
    line-height: 2.8em; 
    color: #fff; 
} 

ul#menu li a 
{ 
    padding: 10px 20px; 
    font-weight: bold; 
    text-decoration: none; 
    line-height: 2.8em; 
    background-color: #e8eef4; 
    color: #151B54; 
} 

ul#menu li a:hover 
{ 
    background-color: #fff; 
    text-decoration: none; 
} 

ul#menu li a:active 
{ 
    background-color: #a6e2a6; 
    text-decoration: none; 
}                      

ul#menu li.selected a 
{ 
    background-color: #fff; 
    color: #000; 
} 

第一張圖片顯示正確的顯示所有的時間,第二個顯示不正確的顯示,我試圖避免。

Correct display all the time

Incorrect display, what I am trying to avoid

回答

2

menucontainer特定寬度

+0

百分比寬度或以像素爲單位? – 2012-02-28 06:50:57

+0

使用像素,百分比寬度將取決於瀏覽器窗口的寬度。像素寬度將保持不變。 – robasta 2012-02-28 06:58:11

+0

真棒謝謝! – 2012-02-28 07:08:16

0

要與單位相一致。如果對h1等元素使用pixels,並且填充也使用容器的像素。百分比是相對於瀏覽器的窗口和像素是絕對的。