我使用bootstrap并尝试将搜索表单放在导航栏下拉菜单中,但我发现表单看起来被压扁了,因为下拉列表的宽度太小。此外,表单元素不是我想要的。我该如何解决这个问题?
我一般都是CSS和网页设计的新手。请帮忙!
目前的布局:
我想要实现的目标:
<header class="navbar navbar-inverse navbar-fixed-top navbar-inverse" role="banner">
<div class="container">
<div class="navbar-header">
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".bs-navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="index.html" class="navbar-brand">Brand</a>
</div>
<nav class="collapse navbar-collapse bs-navbar-collapse" role="navigation">
<ul class="nav navbar-nav">
<li class="active"><a href="index.html">Home</a></li>
<li><a href="#">Browse</a></li>
</ul>
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Locate <b class="caret"></b></a>
<ul class="dropdown-menu">
<form class="navbar-form navbar-left" role="search">
<div class="form-group">
<button type="button" class="btn btn-default navbar-btn"><li class="icon-screenshot"></li></button>
<input type="text" class="form-control" placeholder="Address">
</div>
<div class="btn-group">
<button type="submit" class="btn btn-default">Search</button>
<ul class="dropdown-menu" role="menu">
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
</ul>
</div>
</form>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">USER <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#"><i class="icon-pencil"></i> Link</a></li>
<li><a href="#"><i class="icon-upload"></i> Link</a></li>
<li class="divider"></li>
<li><a href="#"><i class="icon-signout"></i> Link</a></li>
</ul>
</li>
</ul>
</nav>
</div>
</header>
答案 0 :(得分:7)
试试这个:
.navbar-nav>li>.dropdown-menu { width: yourwidth }
您可以添加display: inline-block
,使其宽度自动根据其内容
答案 1 :(得分:2)
您可以在dropdown.less
中增加“min-width”值或在css中新建一行
.dropdown-menu { min-width: 200px }