Bootstrap horizontal dropdown-menu? - html

I'd like a bootstrap dropdown menu where the links are horizontal. Unfortunately, I'm having trouble with getting the width correct. The only way I can seem to make it happen is set the min-width to some arbitrary number. I'd like to do this responsively.
http://jsfiddle.net/3CwzH/
#import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css');
.dropdown-menu>li>a {
display: inline;
}
.dropdown-menu {
min-width: 500px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
Drop it
</button>
<ul class="dropdown-menu" role="menu">
<li>
Google
Facebook
</li>
</ul>
</div>

I have solved your problem. View this JSFiddle for demonstration.
HTML
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">Drop it</button>
<ul class="dropdown-menu" role="menu">
<li> Google
</li>
<li> Facebook
</li>
</ul>
</div>
CSS
#import url('http://getbootstrap.com/dist/css/bootstrap.css');
.dropdown-menu > li {
display: inline-block;
float:left;
}
.open > ul {
display: inline-flex !important;
}

Related

Navbar search box in the dropdown menu crashes other navbar icons

.navbar-default .navbar-nav > .open > a, .navbar-default .navbar-nav > .open > a:focus, .navbar-default .navbar-nav > .open > a:hover {
background-color: transparent !important;
}
.nav > li a.dropdown-toggle {
text-align: right;
}
.dropdown-menu {
min-width: 20px !important;
}
.nav>li{vertical-align:top}
/* navbar-icon */
.nav {
// display: flex;
width: 100%;
}
.navbar-default .navbar-nav > li > a:focus, .navbar-default .navbar-nav > li > a:hover {
background-color: transparent;
}
.nav > li {
display: inline-block !important;
}
.nav_li_last_options {
float: right;
}
<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.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<!--navbar start-->
<nav class="navbar navbar-default navbar-fixed-top navbar_base">
<div class="container-fluid padding_right_0">
<ul class="nav navbar-nav navbar_ul_base" style="max-height: 50px;">
<li><i class="glyphicon glyphicon-comment"></i></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" style="padding: 15px; text-align: left">
<i class="glyphicon glyphicon-search"></i>
</a>
<ul class="dropdown-menu" style="width: 100%;">
<li>
<form class="navbar-form" style="width: 100%; margin: auto">
<div class="input-group input-group-sm">
<input class="form-control" placeholder="Search" id="searchbar" type="text">
<div class="input-group-btn">
<i class="btn btn-default"><i class="glyphicon glyphicon-search"></i>
</i>
</div>
</div>
</form>
</li>
</ul>
</li>
<li class="nav_li_last_options dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" style="padding: 15px;">
<i class="glyphicon glyphicon-option-horizontal"></i>
</a>
<ul class="dropdown-menu dropdown_menu_base">
<li>JavaScript</li>
</ul>
</li>
</ul>
</div>
</nav>
options: bootstrap3(3.3.7) and jquery3
I made navbar that has search icon. When I click search icon, search box in the dropdown menu will be opened.
But, On browser's width < 768, when I click search Icon, navbar and other icons are crashed.
Is there any good way to fix it?
How can I fix it?
According to bootstrap official documentation.
Changing the collapsed mobile navbar breakpoint
The navbar collapses into its vertical mobile view when the viewport is narrower than #grid-float-breakpoint and expands into its horizontal non-mobile view when the viewport is at least #grid-float-breakpoint in width. Adjust this variable in the Less source to control when the navbar collapses/expands. The default value is 768px (the smallest "small" or "tablet" screen).
look Official documentation may help you

bootstrap drop down menu transparent button

$(document).ready(function(){
$('.dropdown > button').mousedown(function(){
$(this).addClass('redClass');
$('.dropdown').addClass('redClass');
});
$('.dropdown > button').mouseup(function(){
$(this).removeClass('redClass');
$('.dropdown').removeClass('redClass');
});
$('.dropdown > button').click(function(){
$(this).addClass('redClass');
$('.dropdown').addClass('redClass');
});
$('.dropdown > button').mouseleave(function(){
$(this).addClass('redClass');
$('.dropdown').addClass('redClass');
});
})
/* Latest compiled and minified CSS included as External Resource*/
/* Optional theme */
#import url('//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css');
body {
margin: 10px;
}
.redClass {
background: transparent;
border: 1px solid transparent;
}
.transparentClass{
background: transparent;
border: 1px solid transparent;
}
<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.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="styles.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown">Home
<span class="caret"></span></button>
<ul class="dropdown-menu">
<li>About us</li>
</ul>
</div>
</div>
I want to design a bootstrap drop down for my angular2 application.I am running into issues.I want a single drop down menu when the user clicks the caret only.But even if I click outside the caret the dropdown menu shows.Another issue is I want both the menu and sub menu to have transparent color whether hovered or clicked.I tried the below css for hover and active,it didn't work.
.dropdown > button {
background-color: transparent;
}
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown">Home
<span class="caret"></span></button>
<ul class="dropdown-menu">
<li>About us</li>
</ul>
</div>
I think there is no way to select parent of an element with css. You can use jQuery to do that:
$(document).ready(function(){
$('.dropdown > button').mousedown(function(){
$(this).addClass('redClass');
$('.dropdown').addClass('redClass');
});
$('.dropdown > button').mouseup(function(){
$(this).removeClass('redClass');
$('.dropdown').removeClass('redClass');
});
})
.redClass {
background: #f00;
}
.transparentClass{
background: transparent;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown">Home
<span class="caret"></span></button>
<ul class="dropdown-menu">
<li>About us</li>
</ul>
</div>

Cant change the button color in bootstrap

I have cretaed this button in Bootstrap.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="col-sm-3">
<div class="dropdown2">
<button class="btn btn-default dropdown-toggle glyphicon glyphicon-shopping-cart" type="button" data-toggle="dropdown">Carello (99)
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="menu1">
<li class="dropdown-header">Dropdown header 1</li>
</ul>
</div>
</div>
I have used some Bootstrap classes for buttons but when I try to change the color of this button in css nothing seems to happen.. How is it possible to change the color of this button in Bootstrap?
Here is my css :
.dropdown-menu{
background: #ff6600;
}
Thanks!
You need to override the css. And I suggest you not to use glyphicon classes on button directly instead use a <i></i> inside the button and set the class on it like in this answer. This way you will get proper alignment. Yours was having some alignment problem
.btn.btn-default,
.btn.btn-default:focus{
background-color:#0066ff;
color:#fff;
}
.btn.btn-default:active,
.btn.btn-default.dropdown-toggle:active,
.btn.btn-default:hover{
background-color:#0099ff;
color:#fff;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="col-sm-3">
<div class="dropdown2">
<button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown"><i class="glyphicon glyphicon-shopping-cart""></i> Carello (99)
<span class="caret"></span></button>
<ul class="dropdown-menu" role="menu" aria-labelledby="menu1">
<li class="dropdown-header">Dropdown header 1</li>
</ul>
</div>
</div>
You are currently using .btn-default. Now you could make use of any of the other default Bootstrap button colors: .btn-primary, .btn-info, .btn-success, .btn-warning, .btn-danger.
Alternatively, you can modify the color of this button to a color of your choosing by writing a style for:
.dropdown2 .btn-default {
background: YOURCOLORHERE;
color: YOURCOLORHERE;
}
Add the required styles like below.
button.btn {
background-color: coral;
color: white;
border-color: red;
}
button.btn:hover {
background-color: darkviolet;
color: white;
border-color: darkviolet;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="col-sm-3">
<div class="dropdown2">
<button class="btn btn-default dropdown-toggle glyphicon glyphicon-shopping-cart" type="button" data-toggle="dropdown"> Carello (99)
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="menu1">
<li class="dropdown-header">Dropdown header 1</li>
</ul>
</div>
</div>

Styling a bootstrap drop down nested in a button group

I nested a drop down menu inside a group of buttons but I'm having a little trouble styling the drop down menu to look like the main buttons. It seems like there should be bootstrap classes to do this without using css?
I want the drop down items to show a dark background when hovered over, just like when the main buttons get hovered over. See pictures below
There looks to be some styling when the main buttons get clicked as well, no styling takes place when the drop down menu items get clicked.
I would like similar text in the drop down as the main buttons
I'm just trying to make things look consistent.
Here is my code with a partially working Fiddle and some pics that show the button group with drop down I'm trying to style.
<div class="btn-group btn-group-lg" role="group" aria-label="...">
<button type="button" class="btn btn-default">House</button>
<button type="button" class="btn btn-default">Apartment</button>
<button type="button" class="btn btn-default">Studio</button>
<div class="btn-group btn-group-lg" role="group">
<button type="button" class="btn btn-default dropdown-toggle"
data-toggle="dropdown" aria-expanded="false">
Other <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li><a>Park</a></li>
<li><a>Beach</a></li>
<li><a>Field</a></li>
<li><a>BackYard</a></li>
<li><a>FrontYard</a></li>
<li><a>Other</a></li>
</ul>
</div>
</div>
no highlighting when hovering over drop down menu items.
The dropdown menu options are notoriously light. If you want to adjust the shade of the hover effect, you can add your own CSS to match whatever theme you're using.
Here's how you'd do it for the default theme:
.btn-group .dropdown-menu li:hover a {
color: #333;
background-color: #E6E6E6;
border-color: #ADADAD;
}
Demo in Stack Snippet
.btn-group .dropdown-menu li:hover a {
color: #333;
background-color: #E6E6E6;
border-color: #ADADAD;
}
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.2/css/bootstrap.css" rel="stylesheet"/>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.2/js/bootstrap.js"></script>
<div class="btn-group btn-group-lg" role="group" aria-label="...">
<button type="button" class="btn btn-default">House</button>
<button type="button" class="btn btn-default">Apartment</button>
<button type="button" class="btn btn-default">Studio</button>
<div class="btn-group btn-group-lg" role="group">
<button type="button" class="btn btn-default dropdown-toggle"
data-toggle="dropdown" aria-expanded="false">
Other <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li><a>Park</a></li>
<li><a>Beach</a></li>
<li><a>Field</a></li>
<li><a>BackYard</a></li>
<li><a>FrontYard</a></li>
<li><a>Other</a></li>
</ul>
</div>
</div>
Just add these to css file to get background color when hovering..
a:link {
text-decoration:none;
color:#2E3D4C;
font-weight: bold;
}
li a:hover {
color:#2E3D4C;
background-color:#C2E0FF;
}
ul.menu li ul {
visibility:hidden;
}
ul.menu li:hover ul {
visibility:visible;
}
ul.menu ul li:hover {
background-color:#6B8FB2;
}
li a:link {
display: block;
padding: 0px;
margin:1px;
}

Bootstrap dropdown caret not showing in Firefox

I want to show a caret on the right side of a bootstrap dropdown button within a button-group.
My code is (see also this fiddle):
<div class="span3 well">
<div class="btn-group btn-block">
<a class="btn btn-primary dropdown-toggle btn-block" data-toggle="dropdown" href="#">
New … <i class="caret pull-right"></i>
</a>
<ul class="dropdown-menu">
<li>1</li>
<li>2</li>
</ul>
</div>
</div>
and
.btn-group .dropdown-toggle {
padding-left: 10px;
padding-right: 10px;
}
In webkit (Safari & Chrome) it looks as intended:
However Firefox does not work:
Did I make a mistake here? Which behavior is correct? What should I do to make it work everywhere?
​
The btn-group was causing the problem:
.btn-block .dropdown-toggle {
padding-left: 10px;
padding-right: 10px;
}
<div class="span3 well">
<div class="btn-block"> <!-- <<< Right here is where I removed btn-group -->
<a class="btn btn-primary dropdown-toggle btn-block" data-toggle="dropdown" href="#">
New … <i class="caret pull-right"></i>
</a>
<ul class="dropdown-menu">
<li>1</li>
<li>2</li>
</ul>
</div>
</div>
http://jsfiddle.net/userdude/KdUdS/12/
It looks the same in Chrome as it does in Firefox.
EDIT
Here's the problem:
.btn-group {
font-size: 0;
position: relative;
vertical-align: middle;
white-space: nowrap; // <<< This here
}
That's on line 3438 of bootstrap.css. I fixed it with:
<div class="btn-block btn-group" style="white-space: normal;">
http://jsfiddle.net/userdude/KdUdS/14/
Now the dropdown elements don't look so hot, but I assume you know that are going to fix that.