How can I make twitter bootstrap's menu dropdown be on hover instead of a click?
1.Hide dropdown-menu on mouseover.
$(document).ready(function() {
$('.nav li.dropdown').hover(function() {
$(this).addClass('open');
}, function() {
$(this).removeClass('open');
});
});
2.Hide dropdown-menu on click.
$(document).ready(function() {
$('.nav li.dropdown').hover(function() {
$(this).addClass('open');
});
});
http://jsfiddle.net/7yMsQ/1/
heres a function I'm using to get the navbar dropdowns to slide down on hover instead of just popping in
$('.navbar .dropdown').hover(function() {
$(this).find('.dropdown-menu').first().stop(true, true).delay(250).slideDown();
}, function() {
$(this).find('.dropdown-menu').first().stop(true, true).delay(100).slideUp()
});
While How to make twitter bootstrap menu dropdown on hover rather than click has been upvoted a lot, with the newer versions of Bootstrap, no need to hack at it.
http://cameronspear.com/blog/twitter-bootstrap-dropdown-on-hover-plugin/ is a replacement for the existing dropdown.js, and lets you enable on hover. No CSS modifications required.
You can simply do this by using only css. In case of button dropdown.
<div class="btn-group btn-hover-group">
Action 1
<ul class="dropdown-menu pull-right">
<li>Action 2</li>
<li>Action 3</li>
</ul>
</div>
Removed data-toggle="dropdown" from
.btn-hover-group > a:hover ~ ul{
display:block;
}
.btn-hover-group > .dropdown-menu:hover{
display:block;
}
I hope this will suffice your purpose.
You could use a bootstrap 4 like this..
<div class="dropdown">
<button class="dropbtn">Dropdown</button>
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</div>
then define the class property value following..it should work
.dropbtn {
background-color: #4CAF50;
color: white;
padding: 16px;
font-size: 16px;
border: none;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f1f1f1;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.dropdown:hover .dropdown-content {display: block;}
Related
I am trying to have two items as links in the top right corner of the page.
I posted my code on codepen for a visual example. Whenever I add padding for the visit button the about goes up on the page.
CSS:
.navigation {
display: flex;
justify-content: space-between;
align-content: center;
&-list {
display: flex;
align-self: center;
list-style: none;
font-size: 2rem;
}
&-item {
&-visit {
background-color: $color-tertiary;
padding: 2rem;
}
}
}
Html:
<div class="container">
<navigation class="navigation">
<h1 class="porto">Porto</h1>
<ul class="navigation-list">
<li class="navigation-item">About</li>
<li class="navigation-item navigation-item-visit">Visit</li>
</ul>
</navigation>
</div>
Try removing the height in &-item and padding-bottom in &-visit.
Most drop down lists in websites' main menus are powered by Javascript, which usually displays some div element containing the list on click or hover. But non Javascript users just can't see the drop down list!
The only alternative I can think of is to display the drop down list as a HTML select element, but nobody does that. Is there a better solution out there?
Non-JavaScript menus are surprisingly common and are often times just as clean and can be more efficient than their JavaScript counterparts. You can use JavaScript but it's important to have graceful degradation if you want your menu to be accessible and functional for all users.
There are many examples of these online but the basic premise is to have a normal navigation menu (using UL and LI elements), and use CSS to change the look and appearance based on the user interaction (such as a hover).
Here is an example of a basic menu that will work without CSS or JavaScript and still be perfectly usable (some of the code taken from this answer: https://stackoverflow.com/a/12279190/937012)
<div class="wrapper">
<navigation role="navigation" class="primary-nav">
<ul role="menubar">
<li role="presentation">
<a role="menu-item" href="#" title="First Link">First Link</a>
</li>
<li role="presentation" class="sub-container"> <a role="menu-item" aria-haspopup="true" href="#" title="Second Link">Second Link</a>
<ul role="menu">
<li role="presentation"> <a role="menu-item" href="#" title="Sub Menu Item 1">Sub Item 1</a>
</li>
<li role="presentation"> <a role="menu-item" href="#" title="Sub Menu Item 2">Sub Item 2</a>
</li>
<li role="presentation"> <a role="menu-item" href="#" title="Sub Menu Item 3">Sub Item 3</a>
</li>
</ul>
</li>
<li role="presentation">
<a role="menu-item" href="#" title="Third Link">Third Link</a>
</li>
</ul>
</navigation>
</div>
As is, this will create a navigation menu (using some accessibility attributes) that is cross-browser and accessible. You can read more about accessibility best practices here: https://www.webaccessibility.com/best_practices.php
You can then apply whichever CSS you like to change the appearance and give the desired "drop-down" effect.
Here is some CSS for the above markup that produces a horizontal menu that features a sub-menu that appears below the second link when the mouse is moved over the second list item.
A {
text-decoration: none;
}
A:HOVER {
color: blue;
}
.wrapper {
width: 90%;
display: block;
}
.primary-nav {
display: block;
margin: 0px auto;
width: 100%;
padding: 0px;
}
.primary-nav UL {
background-color: #ababcd;
list-style-type: none;
margin-left: 0px;
padding-left: 0px;
text-indent: 0px;
}
.primary-nav > UL {
display: inline;
border: solid 1px #000000;
text-indent: 0px;
float: left;
height: 24px;
margin: 0px;
width: 100%;
list-style-type: none;
border-collapse: collapse;
}
.primary-nav LI {
max-width: 150px;
text-align: center;
}
.primary-nav > UL LI {
display: inline;
float: left;
padding: 0px 3px 0px 3px;
width: 32%;
line-height: 24px;
vertical-align: top;
margin-top: 0px;
text-align: center;
}
.primary-nav > UL LI UL {
display: none;
width: 100%;
}
.primary-nav > UL LI.sub-container:HOVER UL {
display: inline-block;
float: left;
margin-left: 0px;
clear: both;
border: inset 1px #898989;
box-shadow: 2px 2px 4px #000000;
}
.primary-nav > UL LI.sub-container:HOVER UL LI {
margin-top: 2px;
text-align: left;
clear: both;
width: 100%;
padding: 0px;
}
.primary-nav LI A:HOVER {
background-color: #cdcdef;
}
.primary-nav LI A {
display: block;
}
.primary-nav > UL LI.sub-container:HOVER UL LI A {
padding: 1px 3px;
margin: 0px 3px;
}
Here is a fiddle that stitches it all together: http://jsfiddle.net/xDaevax/osu7t9ty/
I've built a slider with 4 images using Bootstrap & jQuery, but I can't work out why my images will not resize (as they should automatically, as it is supposed to be responsive).
Any help much appreciated!
<style>
body, html {
padding: 0px;
margin: 0px;
}
.banner {
position: relative;
width: 100%;
overflow: auto;
padding: 0px;
margin: 0px;
}
.banner ul {
padding: 0px;
margin: 0px;
}
.banner li {
list-style: none;
padding: 0px;
margin: 0px;
}
.banner ul li {
float: left;
padding: 0px;
margin: 0px;
min-height: 450px;
background-size: 100% auto;
}
</style>
<div class="banner">
<ul>
<li style="background-image: url('images/Petra 1.jpg');">
</li>
<li style="background-image: url('images/Petra 2.jpg');">
</li>
<li style="background-image: url('images/Petra 3.jpg');">
</li>
<li style="background-image: url('images/Petra 4.jpg');">
</li>
</ul>
</div>
<script>
$(document).ready(function () {
$('.banner').unslider({
speed: 600, //Speed in milliseconds
delay: 3000, // To delay between slide (in milliseconds
keys: true,
fluid: true,
});
});
</script>
The images are loaded as background, and thus not resized according to the container. To resize the background you can use: background-size:cover, see also https://developer.mozilla.org/en-US/docs/Web/CSS/background-size
I want to build an android like main navigation that fits into a Susy Grid. It looks like this:
The code goes here:
HTML:
<div class="container">
<nav>
<ul class="horizontal-list">
<li>
One
</li>
<li>
Two
</li>
<li>
Three
</li>
<li>
Four
</li>
</ul>
</nav>
</div>
SASS:
header.main {
height: $headerHeight;
background: url('images/headerBackground.gif');
.container {
#include container;
#include susy-grid-background;
nav {
#include span-columns(8);
ul.horizontal-list {
#include horizontal-list;
overflow: visible;
li {
#include isolate-grid(2, 8);
padding: 0;
display: table;
a {
// vertical alignment
display: table-cell;
height: $headerHeight / 2;
padding-bottom: 2px;
vertical-align: bottom;
// appearance
color: $greyLight;
font-size: 18px;
text: {
transform: uppercase;
decoration: none;
}
// hover
position: relative;
&:before {
content: '';
display: block;
width: $headerUnderlineGap;
background: $black;
height: $headerHeight;
position: absolute;
top: 0;
margin-left: -$headerUnderlineGap + 1;
}
&:hover {
color: $white;
&:after {
content: '';
display: block;
background: $cyanLight;
width: 114%; // TODO check why space(2, 8) does not work
height: 4px;
position: absolute;
margin: -1px 0 0 1px;
}
}
}
}
}
}
}
}
I feel it's a bit hacky to set the width of the &:after element to 114% and not to space(2, 8). Can anyone tell me, how to set up a horizontal navigation with a Susy grid and an continuous underline, that hovers all the way to the next li element.
Thanks in advance!
space(2,8) doesn't work in that case because 8 is not actually the context: 2 is. You just need space(2,2).
I am trying to center my menu bar with my logo in the middle. right now everything is floating but it wont center to the middle of the page. Also when it is centered i need the background image that i placed on the left and right side of the logo to resize according to the width of the page - here is a link to how it looks live - Menu Test
on my website i still have the original menu I created where I placed the logo behind the menu bar and set a longer width so that the background would stretch but it won't auto adjust because of it.... Current Menu
I know my code is not perfect so please just bear with me
html
<div id="access">
<div class="menu-container">
<ul id="menu-left" class="menu">
<li class="menu-item">
Home
</li>
<li class="menu-item">
About
</li>
<li class="menu-item">
Services
</li>
</ul><!--END of menu-navigation-left-->
<ul id="menu-center">
<li class="menu-item">
<img src="images/logo.png" alt="Menu">
</li>
</ul> <!--close div center-->
<ul id="menu-right" class="menu">
<li class="menu-item">
Blog
</li>
<li class="menu-item">
Contact
</li>
<li class="menu-item">
Portfolio
</li>
</ul><!--END of menu-navigation-left-->
</div><!--END of menu-navigation-container-->
</div><!--END of access-->
css
header {
position:fixed;
}
#access {
width:100%;
overflow:hidden;
left:50%;
}
#access ul.menu{
display: inline-block;
}
#access ul {
}
#access ul a{
display:block;
}
#access ul#menu-left {
height:120px;
background-image:url(../images/menu.png);
}
#access ul#menu-center {
height:120px;
}
#access ul#menu-right {
height:120px;
background-image:url(../images/menu.png);
}
ul, li {
margin:0px;
padding:0px;
list-style:none;
float:left;
display:block;
}
#access a {
display: block;
font-size: 16px;
line-height: 15px;
padding: 13px 10px 12px 10px;
text-transform: titlecase;
text-decoration: none;
font:"Mc1regular", Arial, sans-serif;
}
a:link{
color:#fff;
}
a:visited{
color:#fff;
}
This should sort out your alignment issues.. just replace with your specs. I would just have one menu and centre it.
PLEASE NOTE, YOUR HEADER POSITION IS FIXED> position:relative would be better..
div.container {
width: 1160px;
margin: auto;
margin-top: -1;
margin-bottom: -1;
padding: 0;
padding-top: 10px;
background-color: #2d2d2d;
}
div.box {
margin: auto;
margin-top: 20px;
margin-bottom: 20px;
padding: 10px;
padding-bottom: 20px;
border: solid 1px #A29060;
background-color: #000;
overflow: hidden;
width: 940px;
}
div.top {
text-align: left;
margin: auto;
margin-left: 20px;
padding-top: 12px;
padding-bottom: 11px;
font-weight: normal;
font-size: 14px;
overflow: hidden;
width: 980px;
text-transform: uppercase;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
}
li {
float: left;
padding-right: 20px;
}
a {
display: block;
color: #a29060;
text-decoration: none;
}
<div class="container">
<div class="box">
<div class="top">
<ul >
<li>Contact</li>
<li>Policies</li>
<li><img class="logo" src="images/logo.jpg" alt="logo" /></li>
<li>Policies</li>
</ul>
</div>
see this fiddle
http://jsfiddle.net/yvytty/RJ4Yp/
You can also have a look at this (it's not finished) but it has the basic layout sorted, menus etc
https://www.yve3.com/index.html
This is also a link to a great forum, HTML.net. They give you good opinions of your site and have a lot of expertise (just like here)
http://www.html.net/forums/