2011-03-28 73 views
1

我想將導航欄按鈕居中,但出於某種原因,它們太靠右了。爲什麼是這樣??中心導航按鈕

HTML:

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="utf-8"> 
    <link href="css/mainStyle.css" rel="stylesheet" type="text/css">  
    <script type="text/javascript" src="js/jquery.js"></script> 

    <script language="javascript"> 

       function start() { 
        hideAll(); 
        $('#about').show(); 
       } 

       function hideAll() { 
        $('#home').hide(); 
        $('#contact').hide(); 
       } 

       function slideAll() { 
        $('#home').slideUp(); 
        $('#contact').slideUp(); 
       } 

       $(document).ready(function() { 
        start(); 
       }); 
     </script> 
</head> 
<body> 

    <style type="text/css"> 

     body { 
      background-color: #f3f3f3; 
     } 
     div.banner { 
      width: 800px; 
      height: 200px; 
      margin-left: auto; 
      margin-right: auto; 
      border: 1px solid black; 
      text-align: center; 
      background: white; 
     } 
     div.main { 
      width: 800px; 
      height: auto; 
      margin: 40px auto 50px auto; 
      background-color: white; 
      padding: 20px; 
     } 
     p { 
      font-family: Helvetica; 
      font-weight: 100; 
      text-indent: 0px; 
      margin-bottom: 40px; 
     } 
     div.heading { 
      font-size: large; 
      text-transform: uppercase; 
      font-family: Helvetica; 
      font-weight: bolder; 
      margin-bottom: 20px; 
     } 

     .answer { 
      font-family: Helvetica; 
      font-weight: 100; 
      margin-left: 60px; 
     } 
     p.question { 
      font-family: Helvetica; 
      margin: 0px 0px 0px 0px; 
      text-indent: -13px; 
      padding-left: 13px 
     } 
     #shadow { 
      -webkit-box-shadow: 0px 0px 4px #000000; 
      -moz-box-shadow: 0px 0px 4px #000000; 
      box-shadow: 0px 0px 4px #000000; 
     } 

    </style> 

    <div class="banner"> 
     BANNER 
    </div> 


    <nav id="navcontainer"> 
     <ul id="navlist"> 
      <li id="button"><a onclick="hideAll(); $('#home').slideDown();" id="current">Home</a></li> 
      <li id="button"><a href="#">Past Summer Camps</a></li> 
      <li id="button"><a onclick="hideAll(); $('#contact').slideDown();">About Summer Camps</a></li> 
      <li id="button"><a href="#">Apply</a></li> 
      <li id="button"><a onclick="hideAll(); $('#contact').slideDown();">Contact</a></li> 
      <li id="button"><a href="#">Photo Gallery</a></li> 
     </ul> 
    </nav> 

    <div class="main" id="shadow"> 


    </div> 

      <div id="about"> 

      </div> 


     <div id="contact"> 
      CONTACT 
     </div> 
    </div> 


</body> 
</html> 

和CSS:

#navcontainer ul 
{ 
    list-style-type: none; 
    width: 100%; 
    margin-left: auto; 
    margin-right: auto; 
    text-align: center; 
    margin-top: 40px; 
} 

#button { display: inline; } 

li a 
{ 
    text-decoration: none; 
    color: black; 
    padding: 8px; 
    margin-right: 30px; 
    -moz-border-radius: 6px; 
    -webkit-border-radius: 6px; 
    border-radius: 6px; 


    background: #eeeeee; /* old browsers */ 
    background: #eeeeee; /* old browsers */ 
    background: -moz-linear-gradient(top, #eeeeee 0%, #A0A0A0 100%); /* firefox */ 
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#eeeeee), color-stop(100%,#A0A0A0)); /* webkit */ 
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#eeeeee', endColorstr='#A0A0A0',GradientType=0); /* ie */ 

    -webkit-box-shadow: 0px 0px 3px #000000; 
    -moz-box-shadow: 0px 0px 3px #000000; 
    box-shadow: 0px 0px 3px #000000; 

    text-transform: uppercase; 
    font: 22px 'HomeRemedy', Arial, sans-serif; 
    font-size: 12px; 
    font-weight: bold; 
} 

li a:hover 
{ 
    background: #353535; 
    color: #fff; 
} 
+0

我仍然不知道是什麼問題,但它固定通過添加CSS重置代碼: – 2011-03-29 00:50:46

+0

如果有人看到原始問題,請告訴我。 – 2011-03-29 00:51:31

回答

0

你有你的鏈接右邊距。減少一半,並添加一個左邊距:

margin-right: 15px; 
margin-left: 15px; 

http://jsfiddle.net/CsJ8J/

+0

我試過了,但沒有運氣。我也有一個圖像相同的問題,但我沒有設置我的圖像屬性... – 2011-03-29 00:45:19

+0

哦,你必須使用IE8。在切換到IE8模式之前,我沒有看到更大的問題。 – gilly3 2011-03-29 01:41:10

+0

如果我曾經使用IE8,請立即殺死我。我在FF4上。 – 2011-03-29 05:27:22

0
<style> 
ul 
{ 
list-style-type:none; 
margin:0; 
padding:0; 
} 
li 
{ 
display:inline; 
} 
</style> 

只添加這上面,它會他們居中