Bootstrap Dropdown on Hover Removing Styles
Currently I'm trying to make it so that my bootstrap dropdown happens only on hover instead of on click.
I have a 100% width dropdown all styled and ready with on click method, but when I change the CSS to make the dropdown appear on hover it seems to remove the styles or overwrite them?
Any help would be brilliant.
The HTML
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><i class="ion-navicon icon"></i><span class="caret"></span></a>
<ul class="dropdown-menu">
<li>
<a href="#">Another action</a>
<a href="#">Another action</a>
<a href="#">Another action</a>
<a href="#">Another action</a>
</li>
<li><a href="#">Something else here</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">Separated link</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">One more separated link</a></li>
</ul>
</li>
My CSS
.nav > li.dropdown.open { position: static; }
.nav > li.dropdown.open .dropdown-menu
{
display:table;
width: 100%;
text-align: center;
left:0;
right:0;
margin-top:-1px;
box-shadow: none;
border:none;
background:#252525;
}
.dropdown-menu>li { display: table-cell; }
But when I add the below code it instantly changes back to the original styles?
.dropdown:hover .dropdown-menu {
display: block;
margin-top: 0; // remove the gap so it doesn't close
}
If it makes any difference the backend is Wordpress.
Thanks
CSS
html
twitter-bootstrap
- asked 9 years ago
- Sandy Hook
2Answer
Try this in your css file:
ul.nav li.dropdown:hover > ul.dropdown-menu {
display: block;
}
- answered 8 years ago
- G John
@media (min-width: 767px) {
.navbar-default .tablemenu {
border-radius: 0px;
background: #E7E7E7;
padding: 0;
margin: 0;
}
.navbar-default .tablemenu > li > a {
padding: 5px 0;
margin: 0;
line-height: 20px;
color: #777;
}
.navbar-default ul.nav li:hover > ul.dropdown-menu,
.navbar-default .nav > li.dropdown.open .dropdown-menu {
display: table;
width: 100%;
text-align: center;
box-shadow: none;
border: none;
}
.navbar-default .tablemenu-large {
position: static !important;
}
.navbar-default .dropdown-menu > li {
display: table-cell;
}
}
@media (max-width: 768px) {
.tablemenu > li > ul > li {
list-style: none;
}
.tablemenu > li > ul > li > a {
display: block;
padding: 3px 5px;
}
.tablemenu > li > a:hover,
.tablemenu > li > a:focus {
text-decoration: none;
background-color: #E7E7E7 !important;
}
}
<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" />
<div class="navbar navbar-default">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Brand</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="dropdown tablemenu-large ">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"> <span class="caret"></span>
</a>
<ul class="dropdown-menu tablemenu">
<li> <a href="#">Another action 1</a> <a href="#">Another action 2</a> <a href="#">Another action 3</a> <a href="#">Another action 4</a>
</li>
<li><a href="#">Something else here A</a>
</li>
<li role="separator" class="divider"></li>
<li><a href="#">Separated link B</a>
</li>
<li role="separator" class="divider"></li>
<li><a href="#">One more separated link C</a>
</li>
</ul>
</li>
</ul>
</div>
</div>
</div>
<div class="container">
<div class="well well-lg">Bootstrap 3</div>
<p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up
one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum
et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section
1.10.32. Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia,</p>
<p>looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus
Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line
in section 1.10.32. Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College
in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source.</p>
<p>Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line
of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32. Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.
Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable
source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first
line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.</p>
</div>
- answered 8 years ago
- B Butts
Your Answer