2016-05-10 109 views
1

我是相當新的HTML和CSS,所以很抱歉,如果這是一個相當明顯的問題我的導航欄居中,直到我添加引導類,任何人都可以幫我解決什麼是導致這種衝突?如何將導航中心對齊?

ul { 
 
    margin: 0; 
 
    padding: 0; 
 
    text-align: center; 
 
    position: relative; 
 
    display: inline-block; 
 
} 
 
li { 
 
    display: inline; 
 
    list-style: none; 
 
    height: 100px; 
 
    line-height: 100px; 
 
} 
 
ul li { 
 
    height: 100px; 
 
} 
 
a:link, 
 
a:visited { 
 
    display: inline-block; 
 
    margin-right: -4px; 
 
    width: 120px; 
 
    font-weight: bold; 
 
    color: black; 
 
    text-align: center; 
 
    padding: 4px; 
 
    text-decoration: none; 
 
    text-transform: uppercase; 
 
} 
 
#circle { 
 
    background-color: #AAAAAA; 
 
    border-radius: 50%; 
 
    display: inline-block; 
 
    width: 100px; 
 
    height: 100px; 
 
} 
 
#nav { 
 
    padding-top: 10px; 
 
    padding-bottom: 10px; 
 
} 
 
.line { 
 
    text-decoration: overline; 
 
    text-align: center; 
 
    vertical-align: middle; 
 
    display: inline; 
 
} 
 
#full { 
 
    width: 100%; 
 
    text-align: center; 
 
} 
 
#K { 
 
    color: white; 
 
    font-size: 48px; 
 
    font-family: 'Lucida Sans Typewriter', 'Lucida Console', monaco, 'Bitstream Vera Sans Mono', monospace; 
 
} 
 
.box { 
 
    display: inline; 
 
    padding-left: 30px; 
 
    padding-right: 30px; 
 
}
<div id="full" class="row"> 
 
    <ul id="nav"> 
 
    <li> 
 
     <div class="box col-md-2 col-sm-2 col-xs-12"> 
 
     <a href=csshomepage.html> 
 
      <p class="line">About&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p> 
 
     </a> 
 
     </div> 
 
    </li> 
 
    <li> 
 
     <div class="box col-md-2 col-sm-2 col-xs-12"> 
 
     <a href="#images"> 
 
      <p class="line">Projects&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p> 
 
     </a> 
 
     </div> 
 
    </li> 
 
    <li> 
 
     <div class="box col-md-4 col-sm-4 hidden-xs" id="circle"> 
 
     <a href="#images"> 
 
      <p id="K">K</p> 
 
     </a> 
 
     </div> 
 
    </li> 
 
    <li> 
 
     <div class="box col-md-2 col-sm-2 col-xs-12"> 
 
     <a href="#links"> 
 
      <p class="line">Examples&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p> 
 
     </a> 
 
     </div> 
 
    </li> 
 
    <li> 
 
     <div class="box col-md-2 col-sm-2 col-xs-12"> 
 
     <a href="#links"> 
 
      <p class="line">Contact &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p> 
 
     </a> 
 
     </div> 
 
    </li> 
 
    </ul> 
 
</div>

+0

如果你想使用bootstrap,你應該檢查他們的網站。在組件下查找導航欄。 –

回答

0

當您使用CSS引導那你爲什麼要編寫自己的CSS? 代碼中的主要問題是使用&nbsp;,當您在不同的屏幕尺寸上查看您的網站時,這會造成很多麻煩。

你的代碼改成這樣:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
 
<!-- Latest compiled and minified CSS --> 
 
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous"> 
 

 
<!-- Optional theme --> 
 
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous"> 
 

 
<!-- Latest compiled and minified JavaScript --> 
 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script> 
 

 
<nav class="navbar navbar-default"> 
 
    <div class="container-fluid"> 
 
    <!-- Brand and toggle get grouped for better mobile display --> 
 
    <div class="navbar-header"> 
 
     <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false"> 
 
     <span class="sr-only">Toggle navigation</span> 
 
     <span class="icon-bar"></span> 
 
     <span class="icon-bar"></span> 
 
     <span class="icon-bar"></span> 
 
     </button> 
 
     <a class="navbar-brand" href="#">Brand</a> 
 
    </div> 
 

 
    <!-- Collect the nav links, forms, and other content for toggling --> 
 
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> 
 
     <ul class="nav navbar-nav"> 
 
     <li class="active"><a href="#">About Us<span class="sr-only">(current)</span></a> 
 
     </li> 
 
     <li><a href="#">Project</a> 
 
     </li> 
 
     <li class="dropdown"> 
 
      <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Examples<span class="caret"></span></a> 
 
      <ul class="dropdown-menu"> 
 
      <li><a href="#">Action</a> 
 
      </li> 
 
      <li><a href="#">Another action</a> 
 
      </li> 
 
      <li><a href="#">Something else here</a> 
 
      </li> 
 
      <li role="separator" class="divider"></li> 
 
      <li><a href="#">Separated link</a> 
 
      </li> 
 
      <li role="separator" class="divider"></li> 
 
      <li><a href="#">One more separated link</a> 
 
      </li> 
 
      </ul> 
 
     </li> 
 
     </ul> 
 
     <form class="navbar-form navbar-left" role="search"> 
 
     <div class="form-group"> 
 
      <input type="text" class="form-control" placeholder="Search"> 
 
     </div> 
 
     <button type="submit" class="btn btn-default">Submit</button> 
 
     </form> 
 
     <ul class="nav navbar-nav navbar-right"> 
 
     <li><a href="#">Contact</a> 
 
     </li> 
 
     
 
     </ul> 
 
    </div> 
 
    <!-- /.navbar-collapse --> 
 
    </div> 
 
    <!-- /.container-fluid --> 
 
</nav>

不要用你的CSS,只是改變必要的HTML內容。

參考:Bootstrap