简体   繁体   English

Bootstrap 3导航栏移动视图-UL和同一行上的链接不是新行

[英]Bootstrap 3 navbar mobile view - ul and links on same line not new lines

Working on Bootstrap 3 navbar header, using one of the default examples. 使用默认示例之一,处理Bootstrap 3导航栏标头。 All the content is put on new lines when collapsing into the mobile view. 折叠到移动视图中时,所有内容都会换行。

I want to put ul and links on the same line, ideally on groups of lines instead of one line per item. 我想将ul和链接放在同一行上,理想情况下放在行组上,而不是每个项目一行。 How do I go about this the best way, do bootstrap provide any good tools for doing this? 我该如何以最好的方式进行操作,引导程序是否提供了执行此操作的任何好的工具? the code example is default bootstrap navbar code. 该代码示例是默认的引导导航栏代码。

 <!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap Example</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> </head> <body> <nav class="navbar navbar-inverse"> <div class="container-fluid"> <div class="navbar-header"> <a class="navbar-brand" href="#">WebSiteName</a> </div> <ul class="nav navbar-nav"> <li class="active"><a href="#">Home</a></li> <li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#">Page 1 <span class="caret"></span></a> <ul class="dropdown-menu"> <li><a href="#">Page 1-1</a></li> <li><a href="#">Page 1-2</a></li> <li><a href="#">Page 1-3</a></li> </ul> </li> <li><a href="#">Page 2</a></li> <li><a href="#">Page 3</a></li> </ul> </div> </nav> <div class="container"> <h3>Navbar With Dropdown</h3> <p>This example adds a dropdown menu for the "Page 1" button in the navigation bar.</p> </div> </body> </html> 

You can achieve that by making the .nav > li elements display: inline-block; 您可以通过display: inline-block; .nav > li元素来实现这一点display: inline-block; , but only do that when the screen size is at max-width: 767px because that is when Bootstrap 3 navbar collapses by default. ,但仅当屏幕尺寸为max-width: 767px时才这样做max-width: 767px因为那是默认情况下Bootstrap 3 navbar折叠的时间。

 @media screen and (max-width: 767px) { .nav>li { display: inline-block !important; } } 
 <!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap Example</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> </head> <body> <nav class="navbar navbar-inverse"> <div class="container-fluid"> <div class="navbar-header"> <a class="navbar-brand" href="#">WebSiteName</a> </div> <ul class="nav navbar-nav"> <li class="active"><a href="#">Home</a></li> <li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#">Page 1 <span class="caret"></span></a> <ul class="dropdown-menu"> <li><a href="#">Page 1-1</a></li> <li><a href="#">Page 1-2</a></li> <li><a href="#">Page 1-3</a></li> <li><a href="#">Page 2</a></li> <li><a href="#">Page 3</a></li> </ul> </li> <li><a href="#">Page 2</a></li> <li><a href="#">Page 3</a></li> <li><a href="#">Page 4</a></li> <li><a href="#">Page 5</a></li> <li><a href="#">Page 6</a></li> </ul> </div> </nav> <div class="container"> <h3>Navbar With Dropdown</h3> <p>This example adds a dropdown menu for the "Page 1" button in the navigation bar.</p> </div> </body> </html> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM