My application has 6 dropdowns
This is the code for two of them,(note: i wrapped everything in container1 class,at the start of the code.
<div class="container1">
<div class="row">
<div class="col-sm-2 col-xs-4">
<div class="btn-group" role="group" aria-label="...">
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria- expanded="true">
Dropdown
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Action</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Another action</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Something else here</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Separated link</a></li>
</ul>
</div>
</div>
</div>
<div class="col-sm-2 col-xs-4">
<div class="btn-group" role="group" aria-label="...">
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-expanded="true">
Dropdown
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Action</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Another action</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Something else here</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Separated link</a></li>
</ul>
</div>
</div>
</div>
</div>
</div>
As you see i wrapped everything in a class called container1,it is made by be.
Here is what my class container1 has
.container1 {
margin-right: 200px;
margin-left: 200px;
}
And it works like magic,this is what i get(as you see the space between them is smaller)
Question: My method works well,but it is not responsive,when i make my browser screen smaller.This is what i get
but if i leave it as it is with default bootstrap,with this big space between them,i get an awesome responsiveness.
How would you make the space between dropdowns smaller,and in the same time leave the dropdown to remain responsive as bootstrap by default does,for small devices.
Thank you for your time.
I think the problem with the responsivness comes from .container1 class which decreases the width that col-**-** classes use. If you want your dropdown menus to be in the center of the .row div, use add text-align: center; in the .row div and remove the margin-right: -15px; and margin-left: -15px; from the .row (you can create custom class .margin-ignore { margin: 0 !important; } and add it to the .row div. Also, replace col-xs-4 with col-xs-6 because the dropdown buttons have bigger width that col-xs-4 in some cases. The final result may look like this:
JSFiddle: https://jsfiddle.net/0n8xmy7a/2/
Try resize the screen and look does it fit for you.
If you still does not like how and when the dropdown menus take their new position you can write your own column grid class and there write explicitly the width of screen when the class to trigger and the width of the elements that hold this class.
Good luck!
Instead on using margins, you could use max-width to keep the buttons close together on large screens.
.container1 {
max-width: 800px;
margin: 0 auto;
}
Related
I'm trying to make a down like bootstrap dropdown, but I want to make the div position dynamic, how can I do it according to the screen size?
When IAMBUTTON is clicked, jquery automatically writes the "transform: translate" I have specified below. Likewise, when I click on the "New dropdown" button that I want to do, I want transform: translate to be added.
<div class="col-sm-1 col-12 mb-1 mb-sm-0">
<button class="btn btn-icon btn-outline-secondary" type="button" id="dropdownMenuButton1001" data-bs-toggle="dropdown" aria-expanded="false">
IAMBUTTON
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuButton1001">
<li class="dropdown-item">
<a tabindex="-1" href="#">HTML</a>
</li>
<li class="dropdown-item">
<a tabindex="-1" href="#">CSS</a>
</li>
<li class="dropdown-submenu dropdown-item" v-on:click="openMenu">
<a class="test dropstart" tabindex="-1" data-popper-placement="left-start">New dropdown <span class="caret"></span>
</a>
<ul class="dropdown-menu dropstart" data-popper-placement="left-start" style="transform: scale(1);">
<li class="dropdown-item">
<a tabindex="-1" href="#">2nd level dropdown</a>
</li>
<li class="dropdown-item">
<a tabindex="-1" href="#">2nd level dropdown</a>
</li>
</ul>
</li>
</ul>
</div>
position: absolute;
inset: auto auto 0px 0px;
margin: 0px;
transform: translate(1071px, -407px);
I am using boostrap4.
I am trying to apply below css to the html elements.
.req
{
border-left: 2px solid #FF6600;
}
it is working fine with input elements but not worked with Select2 dropdown element.
Please help
Select2 Bootstrap Theme
For Select2 drop down theme,
Apply the css to the span like this,
<span class="select2-selection select2-selection--single form-control input-lg" role="combobox" aria-haspopup="true" aria-expanded="false" tabindex="0" aria-labelledby="select2-e8ez-container" style="
border: 2px solid #FF6600;">
Drop Downs
For just Drop downs, you will need to give the css class to button, see an example below,
HTML
<div class="dropdown">
<button class="btn btn-default dropdown-toggle req" type="button" id="menu1" data-toggle="dropdown">Tutorials
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="menu1">
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">HTML</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">CSS</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">JavaScript</a></li>
<li role="presentation" class="divider"></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">About Us</a></li>
</ul>
</div>
CSS
Your css lass needs to have !important in it.
.req
{
border-left: 2px solid #FF6600 !important;
}
Example
https://codepen.io/anjanasilva/pen/WaMxBR
Hope this helps.
I tried to make this part of my code hoverable using CSS only but didn't work, I followed steps right here, http://www.w3schools.com/howto/howto_css_dropdown.asp , But i couldn't put anything correctly in its place on my code, I either make the hoverable or instead i make the entire .list hoverable but yet the .list doesn't work hover hover
<nav class="navbar navbar-toggleable-md navbar-light">
<div class="collapse navbar-collapse" id="navbarNavDropdown">
<ul class="navbar-nav">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<div class="list">
<a class="dropdown-item" href="#">1</a>
<a class="dropdown-item" href="#">2</a>
<a class="dropdown-item" href="#">3</a>
<a class="dropdown-item" href="#">4</a>
<a class="dropdown-item" href="#">5</a>
</div>
</div>
</li>
</ul>
</div>
</nav>
CSS (What I've tried by myself)
<style>
.dropdown-menu {
visibility: hidden;
}
.dropdown-menu:hover > .list {
visibility: visible;
}
</style>
This is a strange structure, but the core of the issue was in your targetting of the wrong classes.
.dropdown{
display: block;
}
.dropdown-menu {
display: none;
}
.dropdown:hover .dropdown-menu {
display: block;
}
<nav class="navbar navbar-toggleable-md navbar-light">
<div class="collapse navbar-collapse" id="navbarNavDropdown">
<ul class="navbar-nav">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<div class="list">
<a class="dropdown-item" href="#">1</a>
<a class="dropdown-item" href="#">2</a>
<a class="dropdown-item" href="#">3</a>
<a class="dropdown-item" href="#">4</a>
<a class="dropdown-item" href="#">5</a>
</div>
</div>
</li>
</ul>
</div>
</nav>
.dropdown-menu:hovern .list {
visibility: visible;
}
this would work, You forgot to remove the '>' from the code that didn't allow css to access the list class, just remove'>' from the code and it may work.
in CSS, any class present in another class can be targeted by just writing the class name with '.'operator.
example- HTML code:
<div class="A">
<div class="B"></div>
</div>
CSS code:
.A .B{
}
this is how you access a subClass with parent class.
I have the following HTML code:
<div style="text-align: center;">
<h2 class="bpcenter" style="color: white;">ONE</h2>
<div class="dropdown">
<button class="btn btn-info dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-expanded="true">
Settings
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Action</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Another action</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Something else here</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Separated link</a></li>
</ul>
</div>
</div>
which right now, is giving me this output:
I'm using the standard bootstrap 3.3.2 css/js files, and I haven't modified anything in the css code for .dropdown or .dropdown>menu.
The button is centered, but the <ul> and its subsequent <li>s are justified left. I'm not sure why.
The problem is that dropdown div expands to 100% width, and inner menu is positioned absolutely relatively to it and has left: 0.
You need to set your button as inline-block in this case menu will position properly:
<div class="dropdown drop-button">
<button class="btn btn-info dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-expanded="true">
Settings
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
<li role="presentation">
<a role="menuitem" tabindex="-1" href="#">Action</a>
</li>
<li role="presentation">
<a role="menuitem" tabindex="-1" href="#">Another action</a>
</li>
<li role="presentation">
<a role="menuitem" tabindex="-1" href="#">Something else here</a>
</li>
<li role="presentation">
<a role="menuitem" tabindex="-1" href="#">Separated link</a>
</li>
</ul>
</div>
CSS:
.drop-button {
display: inline-block;
}
Demo: http://plnkr.co/edit/07w4pjNVnjd7p71fGOCT?p=preview
See the following code:
<div ng-controller="DropdownCtrl">
<div style="height: 100px; overflow-y: auto;">
<!-- Single button -->
<div class="btn-group" dropdown is-open="status.isopen">
<button type="button" class="btn btn-primary dropdown-toggle" ng-disabled="disabled">
Button dropdown <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li>Action
</li>
<li>Another action
</li>
<li>Something else here
</li>
<li class="divider"></li>
<li>Separated link
</li>
</ul>
</div>
</div>
</div>
http://plnkr.co/edit/DwQIi6ipDgN9LIOe5TqR?p=preview
I know that the problem is the height of the div, but I need to leave the height as is.
See the screenshot from my project:
How can I solve that problem?
I use position:fixed but it is not ok, because you use overflow:
if don't use position:fixed, Remove overflow..