keeping search fixed in a dropdown menu - html

I created a dropdown menu with search option in angular JS. when i click on it, a dropdown menu with search option comes. But as i scroll down, search also becomes a part of scroll. I want it to be fixed and placed at position where i clicked.
Here is the code for the dropdown menu.
<div class="dropdown dropdown-scroll" style="margin-top:15px;" >
<button style="width:220px;" class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown">
{selected.ApplicationName}}
</button>
<ul class="dropdown-menu" role="menu">
<li role="presentation">
<div class="input-group input-group-sm search-control" fixed>
<span class="input-group-addon">
<span class="glyphicon glyphicon-search"></span>
</span>
<input type="text" class="form-control" placeholder="Query" ng-model="query"></input>
</div>
</li>
<li role="presentation" ng-repeat='app in applicationArray | filter:query'>
<a ng-click="changeSelected(app)"> {{app.ApplicationName}} </a>
</li>
</ul>
</div>
The output is like this :
Now as i scroll, this search goes up and i cant see it anymore. Also, when i click on *select an application, i want the dropdown to be placed at that location where *select an application is there.
Try this fiddle
http://jsfiddle.net/kyrcha/ULSy3/6/

try this one
use navbar-fixed-top class with your search li
<li role="presentation" class="navbar-fixed-top">
<div class="input-group input-group-sm search-control" fixed>
<span class="input-group-addon">
<span class="glyphicon glyphicon-search"></span>
</span>
<input type="text" class="form-control" placeholder="Query" ng-model="query"></input>
</div>
</li>
EDIT CODE :
I have updated fiddle.Please check it.
HTML :
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1 " ng-controller="ListCtrl">
<li><div class=" fixed-class input-group input-group-sm search-control "> <span class="input-group-addon ">
<span class="glyphicon glyphicon-search"></span>
</span>
<input type="text" class="form-control" placeholder="Query" ng-model="query"></input>
</div>
</li>
<ul class="presentation-li">
<li role="presentation" ng-repeat='item in items | filter:query'> {{item.name}}
</li>
</ul>
</ul>
CSS:
ul.presentation-li li{
list-style: none;
}
ul.presentation-li li a{
color: black;
text-decoration: none;
}
.fixed-class{
position: fixed;
border-width: 0 0 1px;
width : 141px;
top: 37px;
bottom : 35px;
background-color: white;
}

you can add a new css class where you fix high and you overflow-y property to scroll:
.anyClass {
height:150px !important;
overflow-y: scroll !important;
}
In your HTML code, for example you will have something like that:
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton01" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">
</button>
<ul (click)="$event.stopPropagation()" class="dropdown-menu" aria-labelledby="dropdownMenuButton01">
<li>
<input type="text" class="form-control" placeholder="Search">
</li>
<div class="anyClass" >
<app-item-component *ngFor="let item of array"></app-item-component>
</div>
</ul>
</div>
The (click)="$event.stopPropagation()" I added just to stop closing the select window after picking an item.

Related

Design input in select Bootstrap

What I'm looking for is whether there is a bootstrap model in select input that has the arrow + background on the right.
link
CODE HTML:
<div class="bootstrap-select input-group ">
<input type="text" autocomplete="off" name="my_select_label" class="form-control ">
<input type="hidden" name="my_select" value="">
<div class="input-group-btn open">
<button tabindex="-1" type="button" class="btn btn-warning dropdown-toggle active">
<span class="caret"></span>
</button>
<ul tabindex="-1" class="pull-right dropdown-menu warning">
<li class="active">
<a tabindex="-1" href=""></a>
</li>
<li>
<a tabindex="-1" href="Hydrogen">Hydrogen</a>
</li>
<li>
<a tabindex="-1" href="Helium">Helium</a>
</li>
<li>
<a tabindex="-1" href="Lithium">Lithium</a>
</li>
<li>
<a tabindex="-1" href="Beryllium">Beryllium</a>
</li>
<li>
<a tabindex="-1" href="Boron">Boron</a>
</li>
<li>
<a tabindex="-1" href="Carbon">Carbon</a>
</li>
<li>
<a tabindex="-1" href="Nitrogen">Nitrogen</a>
</li>
</ul>
</div>
</div>
I managed to find this model but has two problems:
1.is always open ... not going to click
2.I want to have a structure like the following...(currently is the type list)
<select>
<option>1</option>
<option>2</option>
<option>3</option>
</select>
Does anyone know of an example that meet the above condition?
Thanks in advance!
I think maybe someone will have better way, but in the meantime you can try to use :before like this
HTML
<div class="container">
<div class="col-xs-6 mySelect">
<select class="form-control">
<option>1</option>
<option>2</option>
<option>3</option>
</select>
</div>
</div>
CSS
.mySelect {position: relative}
.mySelect select {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
background-color:transparent;
position:relative;
z-index:5;
}
.mySelect:before {
content: "\f078";
font-family: FontAwesome;
font-size:16px;
width: 34px;
height: 34px;
position: absolute;
top:0;
right:15px;
background-color:orange;
border-radius:0 4px 4px 0;
line-height:34px;
text-align:center;
color:white;
}
Demo
http://getbootstrap.com/components/#btn-dropdowns
I'm wondering that you import the jquery CDN into your source code on the <head> tag?
There may be some problems if you don't import jquery on you site.
And you should edit your <button> tags into like this code.
<button tabindex="-1" type="button" class="btn btn-warning dropdown-toggle active" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
For the 2 problem, This may help you.
https://silviomoreto.github.io/bootstrap-select/

Dropdown container not showing right padding

I'm kinda new to HTML/CSS, and I'm trying to create a page with a login dropdown, but for some reason there's no padding on the right side of it. How can I fix it?
I wasn't able to find a solution.
<div class="navbar navbar-fixed-top navbar-default">
<div class="navbar-header"><a class="navbar-brand">My Site</a>
<a class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="glyphicon glyphicon-bar"></span>
<span class="glyphicon glyphicon-bar"></span>
<span class="glyphicon glyphicon-bar"></span>
</a>
</div>
<div class="container">
<div class="navbar-collapse">
<ul class="nav pull-right navbar-nav">
<li>Sign Up
</li>
<li class="divider-vertical"></li>
<li class="dropdown"> <a class="dropdown-toggle" href="#" data-toggle="dropdown">Sign In <strong class="caret"></strong></a>
<div class="dropdown-menu" style="padding: 10px;min-width:240px;">
Login via
<div class="social-buttons">
<i class="fa fa-facebook"></i> Facebook
</div>
or
<form action="[YOUR ACTION]" method="post" role="form" class="form-horizontal">
<input class="form-control" id="inputEmail1" placeholder="Email" type="email" style="margin-bottom:.5em">
<input class="form-control" id="inputPassword1" placeholder="Password" type="password" style="margin-bottom:.5em">
<div class="checkbox">
<label>
<input type="checkbox">Remember me</label>
</div>
<input class="btn btn-primary" style="margin-top:.75em;width: 100%; height: 32px; font-size: 13px;" type="submit" name="commit" value="Sign In">
</form>
</div>
</li>
</ul>
</div>
</div>
</div>
As Bootstrap Documentation says, sometimes you will need to place your dropdown container in a different position, for those cases you need to add the dropdown-menu-right class like so:
<div class="dropdown-menu dropdown-menu-right" style="padding: 10px;min-width:240px;">
Here's a JSFiddle with the example working:
JSFiddle
Your HTML structure should be changed to reflect the base Bootstrap classes. Pull-right isn't respected in the way you're using it, use navbar-right instead. Check the Docs to see the options you have by default.
*Also this class doesn't exist > <span class="glyphicon glyphicon-bar"></span>
See working example Snippet.
.navbar .dropdown-menu-fb {
padding: 10px;
min-width: 240px;
}
.navbar .navbar-toggle {
padding: 5px 10px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="navbar navbar-fixed-top navbar-default">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-nav" aria-expanded="false"> <i class="fa fa-bars"></i>
</button>My Site
</div>
<div class="collapse navbar-collapse" id="bs-nav">
<ul class="nav navbar-nav navbar-right">
<li>Sign Up
</li>
<li class="dropdown"> <a class="dropdown-toggle" href="#" data-toggle="dropdown">Sign In <span class="caret"></span></a>
<ul class="dropdown-menu dropdown-menu-fb">
<li class="btn btn-default navbar-btn btn-block"> <i class="fa fa-facebook"></i> Login via Facebook
</li>
<li>
<form action="[YOUR ACTION]" method="post" role="form">
<p class="text-center">or Sign Up</p>
<div class="form-group">
<input class="form-control" id="inputEmail1" placeholder="Email" type="email">
</div>
<div class="form-group">
<input class="form-control" id="inputPassword1" placeholder="Password" type="password">
</div>
<div class="form-group">
<div class="checkbox">
<label>
<input type="checkbox">Remember me</label>
</div>
</div>
<div class="form-group">
<input class="btn btn-primary navbar-btn btn-block" type="submit" name="commit" value="Sign In">
</div>
</form>
</li>
</ul>
</li>
</ul>
</div>
</div>
</div>
The container is too big and it go out of the screen?
Work on min-width and let container stay inside the viewport, than focus on padding.
<div class="dropdown-menu" style="padding: 10px;min-width:200px;">
probably you will have to work on dropdown-menu to fix it, we need the css code

How do I make a bootstrap dropdown as wide as its input-group?

I have this:
Here's the code
<div class="col-xs-8 col-xs-offset-2">
<form role="form">
<div class="input-group">
<input type="text" class="form-control">
<div class="input-group-btn">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span>
</button>
<ul id="color-dropdown-menu" class="dropdown-menu dropdown-menu-right" role="menu">
<li class="input">black</li>
<li class="input">white</li>
<li class="input">red</li>
<li class="input">blue</li>
<li class="input">yellow</li>
</ul>
</div>
</div>
</form>
</div>
Fiddle: http://jsfiddle.net/ytqyowgt/
How do I make the dropdown list as wide as the input field + button?
Try setting:
.input-group-btn {
position: static;
}
.dropdown-menu {
width: 100%;
}
check the updated fiddle
Change a bit the structure of your HTML :
<div class="col-xs-8 col-xs-offset-2">
<form role="form">
<div class="input-group">
<div class="input-group-btn">
<input type="text" class="form-control">
<ul id="color-dropdown-menu" class="dropdown-menu dropdown-menu-right" role="menu">
<li class="input">black</li>
<li class="input">white</li>
<li class="input">red</li>
<li class="input">blue</li>
<li class="input">yellow</li>
</ul>
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span>
</button>
</div>
</div>
</form>
</div>
and CSS :
.input-group-btn ul {
width:100%;
}
The only thing is you loose the rounded corners on the button.
http://jsfiddle.net/ytqyowgt/4/

z-index issue in chrome only

I keep getting the same issue when attacking the problem in the method offered on various sites.
Q.How can i set the nav to a z-index of 1000 to appear above all other elements in the site?
I have tried position: absolute & relative' within the fixed div.
I need the nav to be fixed, and expand as bootstrap does but i need the whole nav at any time to appear above anything else.
The nav
<div id='nav_container' class='fixed_nav'>
<div id='nav_div' class=''>
<nav id='navbarnav' class="navbar navbar-default admin_nav_bar" role="navigation">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<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="#"><img class='brand_image' src='assets/images/logo-1-small.png' alt='' /></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 pills">
<li class="active home-pill"><a href="#home" id='home_button'>Home</a></li>
<li class='vids-pill'>Vids</li>
</ul>
<!--
<form class="navbar-form navbar-left" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
-->
<ul class="nav navbar-nav navbar-right pills">
<!--
<li class='login_button'>
<a href='#signin' type="button" class="btn btn-default navbar-btn nav_btn_pad" style='line-height: 0.1;'>Sign in</a>
</li>
<li class='register_button'>
<a href='#register' type="button" class="btn btn-default navbar-btn nav_btn_pad" style='line-height: 0.1;'>Register</a>
</li>
-->
<li class="dropdown">
New <b class="caret"></b>
<ul class="dropdown-menu">
<li class="divider"></li>
<li>Video</li>
<li>Picture</li>
<li>Music</li>
<li class="divider"></li>
</ul>
</li>
<li class='user_button admin-pill'>
<a href='#admin' type="button" class="btn btn-default navbar-btn nav_btn_pad" style='line-height: 0.1;'>Admin</a>
</li>
<li class='user_button myaccount-pill'>
<a href='#myaccount' type="button" class="btn btn-default navbar-btn nav_btn_pad" style='line-height: 0.1;'><? echo $_SESSION['userName']; ?></a>
</li>
<li class='logout_button'>
<a href='http://www.xxxxxxx.co/home/bin/logout/logout.php' type="button" id='logout_button' class="btn btn-default navbar-btn nav_btn_pad" style='line-height: 0.1;'>Logout</a>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
</div>
</div>
The Body of which i wish to appear below but in chrome is appearing above the nav
<div class='container'>
<h3>
New Video
</h3>
<hr />
<div id='new_vid_form' class='' style='position: relative; z-index: 0;'>
<div class="input-group marg_5">
<span class="input-group-addon">Article Title</span>
<input id='new_vid_form_title' type="text" class="form-control" placeholder="Article Title">
<span class="input-group-addon">
<span id="new_vid_form_title_status" class="glyphicon glyphicon-asterisk orange pointer status_box" title="Required field"></span>
</span>
</div>
<div class="input-group marg_5">
<span class="input-group-addon">Short Desc.</span>
<input id="new_vid_form_shortDesc_status" type="text" class="form-control" placeholder="Short Description">
<span class="input-group-addon">
<span id="new_vid_form_shortDesc_status" class="glyphicon glyphicon-asterisk orange pointer status_box" title="Required field"></span>
</span>
</div>
<hr />
<div class="input-group marg_5">
<span class="input-group-addon">Youtube ID</span>
<input id="new_vid_form_youtubeID_status" type="text" class="form-control" placeholder="Youtube Video ID | watch?v=' this bit ' ">
<span class="input-group-addon">
<span id="new_vid_form_youtubeID_status" class="glyphicon glyphicon-asterisk orange pointer status_box" title="Required field"></span>
</span>
</div>
<hr />
<textarea id="new_vid_form_longDesc" class="input-large text_area_fw" placeholder='Long Description'></textarea>
</input>
<hr />
<div class="input-group marg_5">
<span class="input-group-addon">Tags</span>
<input id="new_vid_form_tags" type="text" class="form-control" placeholder="Tags (No more than 10) seperated by comma">
<span class="input-group-addon">
<span id="new_vid_form_tags_status" class="glyphicon glyphicon-asterisk orange pointer status_box" title="Required field"></span>
</span>
</div>
<hr />
<button class='btn btn-default'>Add video</button>
</div>
</div>
The associated CSS
.fixed_nav {
width: 100%;
position: fixed;
top:0;
}
#nav_div {
z-index: 10000;
}
I use the bootstrap Navbar with headroom.js to make it move up & down. I have to set the z-index in the css for the style i used .navbar-fixed-bottom, works for top as well this way , this achives fixed & the z-index, no need to create separate styles, yours are probabaly being overridden you can check in chrome dev tools, in your bootstrap css file look for and .navbar-fixed-top, .navbar-fixed-bottom, then add z-index: 1030; I can't imagine why I used 1030, just needs to be a big enuff to be more than the total amount of elements of the page whatever yours is.
.navbar-fixed-top, .navbar-fixed-bottom {
position: fixed;
right: 0;
left: 0;
z-index: 1030;
}
HTML
<div class="navbar-fixed-bottom">
<ul>
<li>
...
</li>
</ul>
</div>
Possibly way off track, but in your HTML markup your navbar has the id nav_div, but your CSS selector is targeting #navdiv (no underscore)

Twitter bootstrap dropdown goes outside the screen

I want to implement twitter bootstrap dropdown menu, here's my code:
<span class="dropdown">
</b>
<ul class="dropdown-menu">
<li>a</li>
<li>b</li>
<li>c</li>
<li class="divider"></li>
<li>d</li>
</ul>
Dropdown works good, my dropdown is placed next to right edge of the screen and when I click my dropdown-toggle, the list goes outside the screen. It looks like on the screen:
How can i fix it?
adding .pull-right to ul.dropdown-menu should do it
Deprecation Notice: As of Bootstrap v3.1.0, .pull-right on dropdown menus is deprecated. To right-align a menu, use .dropdown-menu-right.
Deprecation Notice 2: As of Bootstrap v5, .dropdown-menu-right is deprecated. For Bootstrap v5, use .dropdown-menu-end.
Since Bootstrap v3.1.0 adding .pull-right is deprecated on dropdown menus. A .dropdown-menu-right should be added to ul.dropdown-menu instead. Docs
For Bootstrap 4, adding dropdown-menu-right works. Here's a working example..
http://codeply.com/go/w2MJngNkDQ
a solution that does not need modifying the HTML only the CSS is
li.dropdown:last-child .dropdown-menu {
right: 0;
left: auto;
}
Its particularly usefull for dynamically generated menus where its not always possible to add the recommended class dropdown-menu-right to the last element
You can use class .dropdown-pull-right with following css:
.dropdown-pull-right {
float: right !important;
right: 0;
left: auto;
}
.dropdown-pull-right>.dropdown-menu {
right: 0;
left: auto;
}
<link href="https://maxcdn.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/twitter-bootstrap/2.3.1/js/bootstrap.min.js"></script>
<div class="dropdown dropdown-pull-right btn-group">
<a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
Open Dropdown
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</div>
in Bootstrap 4 you can use .dropleft
just change to :
<span class="dropleft">
or
add .dropdown-menu-{lg,med,sm,xs}-right to your dropdown-menu
<div class="dropdown-menu dropdown-menu-sm-right" aria-labelledby="dropdown03">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
float-*-right for Bootstrap 4
* = xs, sm, md, lg
I can't leave a comment because my SO level is too low, but I just made sure that the parent container is set to "overflow:hidden" like so (also make sure position is set).
<div style="overflow:hidden;position:relative">
<span class="dropdown">
</b>
<ul class="dropdown-menu">
<li>a</li>
<li>b</li>
<li>c</li>
<li class="divider"></li>
<li>d</li>
</ul>
</div>
If you are using Bootstrap 5, according to documentation:
Dropright:
Trigger dropdown menus at the right of the elements by adding .dropend to the parent element.
<div class="btn-group dropend">
<button type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
Dropright
</button>
<ul class="dropdown-menu">
<!-- Dropdown menu links -->
</ul>
</div>
I encountered this issue recently, and I solved it by addind display="dynamic" to my ngbDropdown (using Angular 12, ngBootstrap 10 and Bootstrap 4):
<div class="row">
<div class="col">
<div ngbDropdown display="dynamic" class="d-inline-block dropdown-menu-right">
<button class="btn btn-outline-primary" id="navbarDropdownForm" ngbDropdownToggle>Sign in</button>
<div ngbDropdownMenu aria-labelledby="navbarDropdownForm">
<form class="px-4 py-3">
<div class="form-group">
<label for="navbarDropdownFormEmail">Email address</label>
<input type="email" class="form-control" id="navbarDropdownFormEmail" placeholder="email#example.com"
autocomplete="username">
</div>
<div class="form-group">
<label for="navbarDropdownFormPassword">Password</label>
<input type="password" class="form-control" id="navbarDropdownFormPassword" placeholder="Password"
autocomplete="current-password">
</div>
<div class="form-check">
<input type="checkbox" class="form-check-input" id="dropdownCheck">
<label class="form-check-label" for="dropdownCheck">
Remember me
</label>
</div>
<button type="submit" class="btn btn-primary">Sign in</button>
</form>
<div class="dropdown-divider"></div>
<button ngbDropdownItem>New around here? Sign up</button>
<button ngbDropdownItem>Forgot password?</button>
</div>
</div>
</div>
</div>