I was wondering how would I re-position a drop-down menu.
What I am trying to achieve is a fake search. So when you click the search button, it activates a drop down with fake dummy results. I am trying to re-position the drop-down to make it look like it came from the search.
Here is my code https://jsfiddle.net/judison/45f50ws9/
.searchBar {
background-color: #67B4AD;
color: white;
width: 280px;
border: none;
}
.dropdown-menu {
right: 100px;
}
.add-on .dropdown > .btn {
border: none;
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
color: white;
background-color: #67B4AD;
}
/* stop the glowing blue shadow */
.add-on .form-control:focus {
color: white;
box-shadow: none;
-webkit-box-shadow: none;
background-color: #67B4AD;
}
<form class="navbar-form navbar-left" role="search">
<div class="searchBarPadding form-group">
<div class="input-group add-on">
<input style="height:22px;" type="text" class="searchBar" placeholder=" Search">
<div class="input-group-btn">
<div class="dropdown">
<button style="height:22px;" class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown"><i class="glyphicon glyphicon-search" style="height:10px;"></i>
</button>
<ul class="dropdown-menu">
<li><a href="#">HTML</a>
</li>
<li class="disabled"><a href="#">CSS</a>
</li>
<li><a href="#">JavaScript</a>
</li>
<li class="divider"></li>
<li><a href="#">About Us</a>
</li>
</ul>
</div>
</div>
</div>
</form>
I would really appreciate the advice!
Heres a very basic example that you can build off of
Codepen http://codepen.io/noobskie/pen/xwEXpv
Just added a click event to the .dropdown-toggle
that will fade in the dropdown and removed the relative postion on
.input-group-btn,
.dropdown{
position:initial;
}
This may be what you're trying to accomplish. You can attach the button with an add on and adjust the width of the dropdown-menu
to the form-control
class so they are the same total width.
#searchForm .form-control { background-color: #67B4AD; color: white; width: 280px; border: none; } #searchForm .dropdown-menu { width: 320px; } #searchForm .btn.btn-default { border: 1px solid #67B4AD; -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075); box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075); color: white; background-color: #67B4AD; } /* stop the glowing blue shadow */ #searchForm .form-control:focus { color: white; box-shadow: none; -webkit-box-shadow: none; background-color: #67B4AD; } @media (max-width: 767px) { #searchForm .form-control { width: 100%; } #searchForm .dropdown-menu { width: auto; } }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" /> <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="#">Link <span class="sr-only">(current)</span></a> </li> <li><a href="#">Link</a> </li> </ul> <form class="navbar-form navbar-left" role="search" id="searchForm"> <div class="input-group"> <input type="text" class="form-control" aria-label="..."> <div class="input-group-btn"> <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> <span class="glyphicon glyphicon-search"></span> </button> <ul class="dropdown-menu dropdown-menu-right"> <li><a href="#">HTML</a> </li> <li class="disabled"><a href="#">CSS</a> </li> <li><a href="#">JavaScript</a> </li> <li class="divider"></li> <li><a href="#">About Us</a> </li> </ul> </div> <!-- /btn-group --> </div> <!-- /input-group --> </form> </div> <!-- /.navbar-collapse --> </div> <!-- /.container-fluid --> </nav>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.