Skip to main content
higgsyd
Inspiring
September 22, 2018
Answered

navigation items close before you can click on them

  • September 22, 2018
  • 3 replies
  • 1349 views

My site is http://v38.ancestry.higgsy.co.uk/index.php

I added a bootstrap navbar but then I found you had to click to open it and I wanted for it to expand on hover, so I added this over-ride code I found on the internet

.dropdown:hover>.dropdown-menu {

display: block;

}

and it seems to work, the only problem now is when you hover and it expands, if you move to pick an item and it closes before you can click it.  On the second or sometimes  third re-attempt it stays expanded ok and sub-items can be clicked.  Can you say why these random closures are happening? Many thanks

This topic has been closed for replies.
Correct answer osgood_

higgsyd wrote

My site is http://v38.ancestry.higgsy.co.uk/index.php

I added a bootstrap navbar but then I found you had to click to open it and I wanted for it to expand on hover, so I added this over-ride code I found on the internet

.dropdown:hover>.dropdown-menu {

display: block;

}

and it seems to work, the only problem now is when you hover and it expands, if you move to pick an item and it closes before you can click it.  On the second or sometimes  third re-attempt it stays expanded ok and sub-items can be clicked.  Can you say why these random closures are happening? Many thanks

Not that I think using hover effects is a good idea as they won't work on mobile but you can use the bit of jquery below to hover over your top-level menu items to expose the sub-menu and close it again on mouseleave:

<script>

$(document).ready(function(){

$('.dropdown').mouseover(function(){

$('.dropdown-menu').css('display','none');

$(this).find('.dropdown-menu').css('display','block');

});

$('.dropdown-menu').mouseleave(function(){

$(this).css('display','none');

});

});

</script>

Obviously you don't need the below if you use the script above:

.dropdown:hover>.dropdown-menu {

display: block;

}

You can also add a click event script to cater for mobile:

<script>

$(document).ready(function(){

$('.dropdown').click(function(){

$('.dropdown-menu').css('display','none');

$(this).find('.dropdown-menu').css('display','block');

});

});

</script>

3 replies

osgood_Correct answer
Legend
October 4, 2018

higgsyd wrote

My site is http://v38.ancestry.higgsy.co.uk/index.php

I added a bootstrap navbar but then I found you had to click to open it and I wanted for it to expand on hover, so I added this over-ride code I found on the internet

.dropdown:hover>.dropdown-menu {

display: block;

}

and it seems to work, the only problem now is when you hover and it expands, if you move to pick an item and it closes before you can click it.  On the second or sometimes  third re-attempt it stays expanded ok and sub-items can be clicked.  Can you say why these random closures are happening? Many thanks

Not that I think using hover effects is a good idea as they won't work on mobile but you can use the bit of jquery below to hover over your top-level menu items to expose the sub-menu and close it again on mouseleave:

<script>

$(document).ready(function(){

$('.dropdown').mouseover(function(){

$('.dropdown-menu').css('display','none');

$(this).find('.dropdown-menu').css('display','block');

});

$('.dropdown-menu').mouseleave(function(){

$(this).css('display','none');

});

});

</script>

Obviously you don't need the below if you use the script above:

.dropdown:hover>.dropdown-menu {

display: block;

}

You can also add a click event script to cater for mobile:

<script>

$(document).ready(function(){

$('.dropdown').click(function(){

$('.dropdown-menu').css('display','none');

$(this).find('.dropdown-menu').css('display','block');

});

});

</script>

BenPleysier
Community Expert
Community Expert
September 23, 2018

To answer your question, have a look at CSS :hover Selector

Having said that, I think that you should heed Nancy OShea​'s reply like I have.

Wappler is the DMXzone-made Dreamweaver replacement and includes the best of their powerful extensions, as well as much more!
Nancy OShea
Community Expert
Community Expert
September 22, 2018

I don't use on Hover triggers anymore.  It's a bad user experience for people on touch screen devices or who may not have a mouse to hover with.  Keep in mind that touch screens are showing up everywhere these days, not just mobile phones and tablets.  So onClick or Tap is a safer trigger for your navigation menu. 

Nancy O'Shea— Product User & Community Expert
ALsp
Legend
September 23, 2018

Bootstrap is a jack of all trades, master at …. [fill in the blank]

Hand-coded menus, or menus made with quality tools, accommodate both mouse and touch users, seamlessly and automatically.

Examples:

Adaptive Menu Magic  (priority-based)

Maxi Menu Magic  (Flexbox + Mega support)