2016-12-14 73 views
0

我正在使用bootstrap爲我的佈局製作投資組合網站,但除了我想製作頂部導航比例並保持居中(每個項目需要所有設備上的寬度的百分比)。 (像apple.com)如何使導航居中,擴展和與屏幕尺寸成比例

這是我的index.html

<!DOCTYPE html> 

<html> 

    <head> 
    <link data-require="[email protected]" data-semver="3.3.7" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" /> 
     <script data-require="[email protected]" data-semver="2.2.4" src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script> 
    <script data-require="[email protected]" data-semver="3.3.7" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 
    <link rel="stylesheet" href="style.css" /> 
    <script src="script.js"></script> 
    </head> 

    <body> 
    <div class="header"> 
     <nav class="navbar navbar-inverse navbar-fixed-top"> 
     <div class="container"> 
      <!-- Brand and toggle get grouped for better mobile display --> 
      <div class="navbar-header"> 
      <button type="button" id="navbarToggle" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#collapsable-nav" 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" ui-sref="app" style="padding:0 0 0 10px;"> 
       <img alt="Brand" class="img-responsive" src="image url here" /> 
       </a> 
      </div> 
      <!-- Collect the nav links, forms, and other content for toggling --> 
      <div class="collapse navbar-collapse" id="collapsable-nav"> 
      <ul class="nav navbar-nav"> 
       <li ui-sref-active="active"> 
       <a ui-sref="home" class="first">Home                  <span class="sr-only">(current)</span> 
       </a> 
       </li> 
       <li ui-sref-active="active"> 
       <a ui-sref="projects">Projects</a> 
       </li> 
       <li ui-sref-active="active"> 
       <a ui-sref="about">About</a> 
       </li> 
       <li ui-sref-active="active"> 
       <a ui-sref="contact">Contact</a> 
       </li> 
       <li ui-sref-active="active"> 
       <a ui-sref="awards">Awards</a> 
       </li> 
      </ul> 
      </div> 
      <!-- /.navbar-collapse --> 
     </div> 
     <!-- /.container-fluid --> 
     </nav> 
    </div> 
    </body> 

</html> 

這是我的風格:

這裏是我的plunker編輯:

https://plnkr.co/edit/bXOx4mwzdbFwEYRtdNd6?p=preview

這裏是我的全螢幕(只是更容易爲您測試和改變屏幕尺寸)提前

https://run.plnkr.co/ZPgTeuYZA2LYl7Et/

感謝。

回答

0

爲了使頂部導航尺度:有在引導文檔的基本模板指令:

複製下面的HTML開始與最小的引導文件的工作:

<!DOCTYPE html> 
<html lang="en"> 
    <head> 
    <meta charset="utf-8"> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --> 

float:none改爲ul.navbar-nav並將width: 19%;改爲ul.navbar-nav > li

.navbar-brand > img { 
    width: auto; 
    height: 44px; 
    max-width: 100%; 
    min-width: 60px; 
    position: absolute; 
    left: 5px; 
} 

ul.navbar-nav { 
    list-style-type: none; 
    text-align: center; 
    float: none; 
} 
ul.navbar-nav > li { 
    margin: 0 auto; 
    max-width: 100; 
    width: 19%; 
    display: inline-block; 
} 

我刪除了ul.navbar-nav > li > a這不影響既沒有物品順序也沒有共同的標記。

+0

確定Banzy,Thak you ..我可以管理縮放,但我需要每個項目才能在所有尺寸上均勻地查看頁面的一部分。 –

+0

已經改變了答案 – Banzay

+0

太好了,因爲這個答案也可以幫助別人,你可以嘗試從> li(s)和> li> a(s)中刪除已公佈的樣式,並且可以告訴我哪些屬性應該分配給每個人,因爲這是一個混亂的問題 –