2016-11-23 62 views
0

Navbar品牌名稱在一條線上運行良好,但當它打破兩條線以上時,品牌名稱從中殿區域出來。更長的品牌名稱在小屏幕上從導航欄外出

所以我想讓這個品牌名稱留在導航欄區域,或者將它隱藏在小屏幕尺寸。

請參考下面圖片鏈接....

Brand name getting outside from nav area

`<nav class="navbar navbar-default navbar-fixed-top"> 
     <div class="container"> 
      <div class="navbar-header"> 


      <!--responsive menu button --> 
       <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> 
        <span class="sr-only">Toggle navigation</span> 
        <span class="icon-bar"></span> 
        <span class="icon-bar"></span> 
        <span class="icon-bar"></span> 
       </button> 




       <!--menu name--> 
       <a class="navbar-brand" href="#">Taibunnesa Khanom Academy Degree College</a> 



      </div> 


      <!-- main menu items --> 
      <div id="navbar" class="navbar-collapse collapse"> 
       <ul class="nav navbar-nav navbar-right"> 
        <li class="active"><a href="#">Home</a></li> 
        <li><a href="#about">About</a></li> 
        <li><a href="#contact">Contact</a></li> 


         <!--droopdown --> 
        <li class="dropdown"> 
         <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <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 class="dropdown-header">Nav header</li> 
          <li><a href="#">Separated link</a></li> 
          <li><a href="#">One more separated link</a></li> 
         </ul> 
        </li> 
       </ul> 
      </div> 
     </div> 
    </nav>` 
+0

'.navbar-brand'有一個'50px'固定高度。 –

+0

你想顯示全名還是隻想隱藏額外的文本? – Aslam

+0

要顯示全名或隱藏完整品牌名稱 –

回答

0

這會的.navbar-brand設置高度爲auto當屏幕寬度得到'768px寬。

@media screen and (max-width: 768px){ 
 
    .navbar-brand{ 
 
     height: auto !important; 
 
    } 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 
 
<meta name="viewport" content="width=device-width, initial-scale=1.0"> 
 
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> 
 
<nav class="navbar navbar-default navbar-fixed-top"> 
 
     <div class="container"> 
 
      <div class="navbar-header"> 
 

 

 
      <!--responsive menu button --> 
 
       <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> 
 
        <span class="sr-only">Toggle navigation</span> 
 
        <span class="icon-bar"></span> 
 
        <span class="icon-bar"></span> 
 
        <span class="icon-bar"></span> 
 
       </button> 
 

 

 

 

 
       <!--menu name--> 
 
       <a class="navbar-brand" href="#">Taibunnesa Khanom Academy Degree College</a> 
 

 

 

 
      </div> 
 

 

 
      <!-- main menu items --> 
 
      <div id="navbar" class="navbar-collapse collapse"> 
 
       <ul class="nav navbar-nav navbar-right"> 
 
        <li class="active"><a href="#">Home</a></li> 
 
        <li><a href="#about">About</a></li> 
 
        <li><a href="#contact">Contact</a></li> 
 

 

 
         <!--droopdown --> 
 
        <li class="dropdown"> 
 
         <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <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 class="dropdown-header">Nav header</li> 
 
          <li><a href="#">Separated link</a></li> 
 
          <li><a href="#">One more separated link</a></li> 
 
         </ul> 
 
        </li> 
 
       </ul> 
 
      </div> 
 
     </div> 
 
    </nav>

+0

它真的很有活力。太棒了,謝謝你。 –

+0

接受我的答案是正確的,如果它適合您的需要。 :) –

0

更新HTML這個(添加自定義類)

<a class="navbar-brand custom-brand" href="#">Taibunnesa Khanom Academy Degree College</a> 

添加到您的CSS。

@media (max-width: 480px){ 

    .custom-brand{ 
    float: left; 
    width: 160px; 
    overflow: hidden; 
    clear: left; 
    text-align: left; 
    text-overflow: ellipsis; 
    white-space: nowrap; 
    } 
} 

小提琴:http://codepen.io/hunzaboy/pen/gLWozx

我相信你會喜歡這個:)

+0

它可以隱藏一些文字。如何將其隱藏全文? –

+0

如果你想隱藏全文。然後添加顯示:無;到我添加的CSS。 – Aslam

+0

@AnimeshDasSumit,請選擇正確的答案作爲答案。根據你的問題,我的答案看起來更具體:) – Aslam