CSS JSP - Dropdown menu keeps opening on submenu focus - html

I would like to create a vertical menu for a website. It works quite well but I still have a problem with the following code:
JSP:
<nav>
<ul>
<li> Saisie assistée (schémas prédéfinis) </li>
<li> Saisie libre </li>
<li> Extourne ou annulation écriture
<ul ">
<li> Annulation écriture jour validé</li>
<li> Extourne écriture antérieure </li>
</ul>
</li>
<li> Consultations/Editions
<ul >
<li> Lots à valider</li>
<li> Lots antérieurs comptabilisés </li>
<li> Listes des schémas habilités </li>
<li> Listes des comptes habilités </li>
</ul>
</li>
<li> Paramètrage/Administration
<ul >
<li> Entités habilitées</li>
<li> Collaborateurs habilités </li>
<li> Habilitations Entité / Comptes </li>
<li> Habilitations Entité / Schémas </li>
<li> Paramétrages Schémas </li>
<li> Import et Export Excel </li>
</ul>
</li>
</ul>
</nav>
CSS:
nav {
width:300px;
}
nav ul {
list-style:none;
margin:0;
padding:0;
}
nav ul li {
position:relative;
background-color: #d23070;
border: 1px solid;
border-top-right-radius: 0.5em;
border-top-left-radius: 0.5em;
border-bottom-right-radius: 0.5em;
border-bottom-left-radius: 0.5em;
margin-bottom: 5px;
}
nav ul li:hover,
nav ul li:FOCUS {
position:relative;
background-color: #3968ab;
border: 1px solid;
border-top-right-radius: 0.5em;
border-top-left-radius: 0.5em;
border-bottom-right-radius: 0.5em;
border-bottom-left-radius: 0.5em;
margin-bottom: 5px;
}
nav a {
color:#e8e8e8;
padding:12px 0px;
display:block;
text-decoration:none;
font-family:tahoma;
font-size:13px;
text-transform:uppercase;
padding-left:20px;
}
nav a:HOVER,
nav a:FOCUS {
background-color:#3968ab;
color:#ffffff;
border-top-right-radius: 0.5em;
border-top-left-radius: 0.5em;
border-bottom-right-radius: 0.5em;
border-bottom-left-radius: 0.5em;
}
nav ul li ul{
background-color:#3968ab;
color:blanc;
border: 1px solid;
border-top-right-radius: 0.5em;
border-top-left-radius: 0.5em;
border-bottom-right-radius: 0.5em;
border-bottom-left-radius: 0.5em;
}
nav a:focus ~ ul{
display:block;
border: 1px solid;
border-top-left-radius: 0.5em;
border-bottom-right-radius: 0.5em;
border-bottom-left-radius: 0.5em;
background:#f1f1f1;
padding-top: 10px;
}
nav ul li ul:hover {
display:block;
border: 1px solid;
border-top-left-radius: 0.5em;
border-bottom-right-radius: 0.5em;
border-bottom-left-radius: 0.5em;
background:#f1f1f1;
padding-top: 10px;
}
nav ul ul {
position:relative;
left:0px;
top:0px;
border-top:1px solid #e9e9e9;
display:none;
}
nav ul ul li {
width:296px;
background:#f1f1f1;
border:0.5px solid #e9e9e9;
border-top:0;
}
nav ul ul li a {
color:#3968ab;
font-size:12px;
text-transform:none;
}
nav ul ul li a:hover {
color:#ffffff;
}
What I want is to open the menu on click and then keep it open, even if we select an element on the list of the subMenu. For now, it remains open if I select an item of the menu's list, but it doesn't if I click on an item of the submenu's list and move my mouse out of it.
This is what I whant when the item of the submenu "Extourne écriture antérieur" is selected(focus).
But When the submenu isn't hover, it is closing by itself. (So I have to keep my mouse on it to keep it open). How can I keep it open even if it is not hovered?
EDIT:
I insist for keeping open the submenu with the item selected when it is not hover by mouse. This is the real problem for me...

To do this, I believe you would need some javascript.
First you would create a style in your CSS that could be added to a child ul to keep it open.
ul.open {
display: block;
}
Then using some jQuery, you listen for a click on an item, and when you detect a click, you find the LI's inner UL and apply the 'open' class to it.
$(document).ready(function(){
$("nav > ul > li a").click(function(){
var parentLi = $(this).parent('li');
var childUl = parentLi.children('ul');
if (childUl.hasClass('open')) {
parentLi.childred('ul').removeClass('open');
} else {
parentLi.childred('ul').addClass('open');
}
return false;
});
});

you can try this one:
First You Create id="top_navigation" in nav
$(document).ready(function () {
var $nav = $('#top_navigation > ul > li');
$nav.hover(
function() {
$('ul', this).stop(true, true).slideDown('fast');
},
function() {
$('ul', this).slideUp('fast');
}
);
});
DEMO HERE
This Should work....

Related

How can i make <li> span full width across <ul>?

I am creating a vertical navigation menu using ul and li I want to make span the full width of ul so I can have underline for each menu item (like this site (http://www.steffenallen.com/index.php))
However, there is a space in li that prevents it from spanning across the parent ul. Could someone tell me how the above website did it? Or, what I need to do?
<nav>
<ul class='menu'>
<li class="menuItem">
About
</li>
<li class="menuItem"> Album
<ul class="submenu">
<li class="submenu-Item">Nepal </li>
<li class="submenu-Item">Seattle</li>
<li class="submenu-Item">South Korea</li>
</ul>
</li>
<li class="menuItem"> Contact </li>
<!-- <li> </li> -->
</ul>
My CSS is
ul,li{
list-style: none;
display: block;
}
ul.menu{
width: 170px;
/*position: absolute;*/
/*width: 100%;*/
/*margin-left: -20px;*/
border: 1px solid orange;
}
ul.submenu{
/*position: absolute;*/
/*left: -999px;*/
/*visibility: hidden;*/
display: none;
}
li{
width:140px;
margin: 0;
padding: 0;
/*width:100%;*/
border-left: 1px blue solid;
border-right: 1px blue solid;
}
span{
display: block;
}
li a, li span {
/*width: 170px;*/
/*width: 100%;*/
border-bottom: #cbcbcb 1px solid;
}
li.menuItem, li.submenu-Item{
text-align: right;
margin: 1em 0em 1em 0em;
}
li.menuitem > a{
color: #808080;
}
li a:hover{
color: steelblue;
}
li.menuItem a.current{
background-color: orange;
}
ul.menu:first-child{
margin-top: 0
}
First things first, your CSS is not well-written and hence a little difficult to understand.
The main problem in your code happens to be the default CSS that is being applied. You can remove that as follows:
ul, li {
margin: 0;
padding: 0;
}
However, I'd suggest you simplify your CSS code as follows. This will still achieve what you are looking for all the while making your code more elegant and easily readable. Please see the code below :
ul, li {
margin:0px;
padding:0px;
}
ul.menu {
border: 1px solid Orange;
width:200px;
}
ul.menu li {
display:block;
list-style-type:none;
}
ul.menu li a {
border-bottom:1px solid #ccc;
display:block;
text-align:right;
text-decoration: none;
}
ul.menu li ul {
display:none;
}
ul.menu li:hover > ul {
display:block;
}
ul.menu li ul li:last-child {
border-bottom:none;
}
See this working below :
ul, li {
margin:0px;
padding:0px;
}
ul.menu {
border: 1px solid Orange;
width:200px;
}
ul.menu li {
display:block;
list-style-type:none;
}
ul.menu li a {
border-bottom:1px solid #ccc;
display:block;
text-align:right;
text-decoration: none;
}
ul.menu li ul {
display:none;
}
ul.menu li:hover > ul {
display:block;
}
ul.menu li ul li:last-child {
border-bottom:none;
}
<nav>
<ul class='menu'>
<li class="menuItem"> About
</li>
<li class="menuItem"> Album
<ul class="submenu">
<li class="submenu-Item">Nepal
</li>
<li class="submenu-Item">Seattle
</li>
<li class="submenu-Item">South Korea
</li>
</ul>
</li>
<li class="menuItem"> Contact
</li>
<!-- <li> </li> -->
</ul>
Hope this helps!!!
On the left side there is the default margin/padding of ULs, so just remove that. It's 40px and depends on browser if margin or padding is used.
ul, li {margin-left: 0; padding-left: 0;}
The space on the right side is caused by your widths, list has 170px, items just 140px.
http://jsfiddle.net/8q9chvbh/

CSS Submenu bar

This is my css code of menu bar which is having an error and not working fine.
ul.semiopaquemenu li a:hover, ul.semiopaquemenu li a.selected{
color: black;
-moz-box-shadow: 0 0 2px #595959; /* CSS3 box shadows */
-webkit-box-shadow: 0 0 5px #595959;
box-shadow: 0 0 5px #595959;
padding-top: 10px; /* large padding to get menu item to protrude upwards */
padding-bottom: 10px; /* large padding to get menu item to protrude downwards */
}
ul.semiopaquemenu li {
position: relative;
}
/*sub menu*/
ul.semiopaquemenu li ul.sub-menu {
display:none;
position: absolute;
LEFT:-22PX;
top:25px;
background-color:#99CCFF;
width:130px;
padding:10px;
border-left: 2px solid #4b6c9e;
border-right: 2px solid #4b6c9e;
border-bottom: 2px solid #4b6c9e;
border-bottom-left-radius: 10px;
-webkit-border-bottom-left-radius: 10px;
-moz-border-radius-bottomleft: 10px;
border-bottom-right-radius: 10px;
-webkit-border-bottom-right-radius: 10px;
-moz-border-radius-bottomright: 10px;
text-decoration:italic;
text-transform:uppercase;
}
ul.semiopaquemenu li:hover ul.sub-menu {
display:block;
}
</style>
This my Html code of menu Bar:
<ul class="semiopaquemenu">
<li><asp:LinkButton ID="lbFAQ" runat="server" PostBackUrl="~/FAQ.aspx">Department</asp:LinkButton>
<ul class="sub-menu">
<li>
Sub Menu 1
</li>
<br />
<li>
Sub Menu 2
</li>
<li>
Sub Menu 3
</li>
<br />
<li>
Sub Menu 4
</li>
</ul>
</li>
</ul>
In this I'm not able to make boxes in sub menu items, so please help with this.
JSFiddle Demo
We are not clear what is actually required but what I understood is you need a box on sub menu item as well
try this JS fiddle
Add this Css
.sub-menu a{
border-bottom: 1px solid #000;
padding: 10px;
display: block;
}
Remove Extra Br in between <li> tags
Also Remove Margin padding form submenu <ul>
ul.semiopaquemenu li ul.sub-menu {
padding:0px;
margin:0px;
list-style:none;
}
change css class ul.semiopaquemenu li ul.sub-menu of attributes to border-bottom: 0px solid #4b6c9e;. The lines are appeared due to mention of px in 2px change it to 0px.

HTML and CSS browser compatibility issue

I have originally created my navigation in Chrome in which the outcome fits perfectly to my needs. I have then found out that Mozilla Firefox won't output the same result, the drop-down menus under Member Action and Admin Related will display vertically instead on horizontally as i wanted. However my biggest dissapointment was testing the navigation in Internet Explorer which won't even show the drop-down menus.
I would really appreciate someone checking the below code and your feedback, Thanks.
Solved the problem by changing one of the lines in css;
navigation ul li {float: left; list-style:none; }
HTML
<div id="navigationContainer">
<div id="navigation">
<ul>
<li class="borderleft">Home </li>
<li>Register </li>
<li>Search cars</li>
<li>Display all cars</li>
<li>Member Actions
<ul> <!-- Open drop down menu -->
<li class="bordertop">Login</li>
<li class="floatLeft">Member Area</li>
<li>Reservation</li>
<li>Contact us</li>
<li>Admin Related
<ul>
<li class="bordertop">Insert new car</li>
<li>Delete a car</li>
</ul>
</li>
</ul>
</div>
</div>
</BODY>
</HTML>
CSS
* {padding: 0%; margin 0%; } /* Overwrites the browser stylesheet */
#navigationContainer {background:url(images/navi.png); width:100%;position: relative; white-space:nowrap; word-spacing:0; }
#navigation {width:1200px; height:65px; position: relative; font-family: Arial; margin: 2px auto; font-size: 125%; }
#navigation ul { list-style-type: none; }
#navigation ul li {float: left; position: relative; }
#navigation ul li a { border-right: 2px solid #e9e9e9; padding: 20px;
display: block; margin: 0 auto; text-align: center; color: black; text-decoration: none; }
#navigation ul li a:hover { background: blue; color: white; }
#navigation ul li ul { display: none; }
#navigation ul li:hover ul {display: block; position: absolute; }
#navigation ul li ul li {float:left; position:relative; }
#navigation ul li:hover ul li a { background: #12aeef; color: white; position:relative; margin: 0px auto; border-bottom: 1px solid white; border-right: 1px solid white; width: 119px; }
#navigation ul li:hover ul li a:hover { background: blue;}
.bordertop { border-top: 1px solid white; }
.borderleft { border-left: 2px solid #e9e9e9;}
Try this
http://jsfiddle.net/Vf3AJ/
Example from: http://www.cssnewbie.com/example/css-dropdown-menu/horizontal.html
EDITED
Misread horizontal for vertical. tested in IE10, FF, and Chrome
As a side note: horizontal menus have serious issues depending on the width of the viewers screen.
CSS
nav {
position: absolute;
top: 0;
right: 0;
margin: 0;
padding: 0;
}
nav li {
list-style: none;
float: left;
}
nav li a {
display: block;
padding: 3px 8px;
text-transform: uppercase;
text-decoration: none;
color: #999;
font-weight: bold;
}
nav li a:hover {
background: blue;
color: white;
}
nav li ul {
display: none;
}
nav li:hover ul, nav li.hover ul {
position: absolute;
display: inline;
left: 0;
width: 100%;
margin: 0;
padding: 0;
}
nav li:hover li, nav li.hover li {
float: left;
}
nav li:hover li a, navbar li.hover li a {
color: #000;
}
nav li li a:hover {
color: white;
}
HTML
<div id="navigationContainer">
<nav id="navigation">
<ul>
<li class="borderleft">Home
</li>
<li>Register
</li>
<li>Search cars
</li>
<li>Display all cars
</li>
<li>Member Actions
<ul>
<!-- Open drop down menu -->
<li class="bordertop">Login
</li>
<!-- A bordertop class is given to this listed element in order to style a top border for in in the external CSS file. -->
<li class="floatLeft">Member Area
</li>
<li>Reservation
</li>
</ul>
</li>
<li>Contact us
</li>
<li>Admin Related
<ul>
<li class="bordertop">Insert new car
</li>
<li>Delete a car
</li>
</ul>
</li>
</ul>
</nav>
</div>

Trying to create CSS nav and having issue with sub elements

I am trying to create a left hand nav and have it close to where I need it except for one problem.
Take a look at the example in this Fiddle.
When the mouse hovers over the "link" items, the cell changes color. But when it hovers over the secondary items, the outer parent li also changes color. I realize this is because the outer li also has a class of "link", but if I take that class off, then the background isn't correct.
Basically, I want the sub elements to stretch border to border in the overall container. Maybe a ul list is not an appropriate control for what I am trying to achieve?
Appreciate any help.
HTML
<div class="nav">
<ul>
<li class="link active">Home</li>
<li class="link">Profile</li>
<li class="navhead">Messages</li>
<li class="link">
<ul>
<li class="link">Open</li>
<li class="link">Closed Closed Closed Closed</li>
</ul>
</li>
</ul>
</div>
CSS
ul {
-webkit-padding-start: 0;
-webkit-margin-before: 0;
-webkit-margin-after: 0;
-webkit-margin-start: 0px;
-webkit-margin-end: 0px;
}
.nav {
font-family:Verdana;
font-size:12px;
width:200px;
}
.nav {
background-color: #F3E0A3;
cursor: default;
border: 1px solid #d2b48c;
border-collapse:collapse;
}
.nav li.navhead {
background-color: #F3E0A3;
border: 1px solid #d2b48c;
border-collapse:collapse;
}
.nav ul {
list-style-image: none;
list-style-position: outside;
list-style: none;
}
.nav li {
margin: 0;
padding: 0;
padding-left: 10px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.nav li .active {
}
.nav li.link {
background-color: #ECE9D8;
}
.nav li.link:hover {
cursor: pointer;
background-color: #e1dfd2;
}
.nav ul li ul {
padding-left: 10px;
}
http://jsfiddle.net/LZqud/7/
HTML:
<li class="link link-with-sub">
<ul class="sub">
<li class="sublink">Open</li>
<li class="sublink">Closed Closed Closed Closed</li>
</ul>
</li>
CSS:
.nav li.link {
background-color: #ECE9D8;
}
.nav ul li ul.sub {
margin-left: -10px;
padding-left:0;
}
.nav ul li ul.sub li {
padding-left: 20px;
}
.nav li.link:hover, .nav ul.sub li.sublink:hover {
cursor: pointer;
background-color: #e1dfd2;
}
.nav li.link, .nav li.link-with-sub:hover {
background-color: #ECE9D8;
}
change the link class that wraps the inner one. so it doesn't change the background when hovered.
http://jsfiddle.net/btevfik/LZqud/6/
<li class="innerlink">
<ul>
<li class="link">Open</li>
<li class="link">Closed Closed Closed Closed</li>
</ul>
</li>
CSS
.nav li.innerlink {
background-color: #ECE9D8;
}
Just as simple as this,
replace the last block of CSS as shown below,
From:
.nav ul li ul {
padding-left: 10px;
}
To:
.nav ul li ul li{
margin-left: -10px;
padding-left: 20px;
}
Hope this is what you need..

submenu pure css and html disappears

I have a menu which has a submenu. the submenu appears when i hover the main menu, but as soon as i try to go down to the submenu it disappears most of the time. Only if i'm very fast I'm able to get to it before it disappears.
HTML:
<header>
<div class="wrapper">
<img src="images/logo.png" width="125" height="20" alt="">
<nav class="fl">
<ul >
<li> Target Groups
<ul>
<li>Manage Target Groups</li>
<li>Create Target Group</li>
</ul>
</li>
<li>Activity</li>
<li>Reports</li>
<li>Settings</li>
<li>Admin</li>
</ul>
</nav>
</div>
<!-- end .wrapper -->
</header>
CSS:
header{
margin-top: 30px;
background: url(../images/header-bg.png) no-repeat;
width: 942px;
height: 76px;
padding: 27px 25px 5px;
}
header .wrapper{
border-bottom: 1px solid #e5e5e5;
float:left;
width: 862px;
padding: 0 40px 5px;
position:relative;
}
header nav{
margin-left: 45px;
}
header nav ul{
z-index: 100;
}
header nav ul li{
display: inline;
margin-right: 35px;
line-height: 20px;
z-index: 100;
}
header nav ul li ul{
display: none;
position:absolute;
width: 962px;
left: 0;
top: 40px;
}
header nav ul li ul li{
float: left;
}
header nav ul li:hover ul{
display:block;
}
header nav ul li a{
font-size:16px;
color: #5b666a;
text-decoration: none;
padding: 5px 10px;
}
header nav ul li a.selected,header nav ul li a:hover{
background: #657073;
color: white;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
}
I'm really stuck, please help...
In order to achieve what you want, it's better to use padding-top for your submenu, instead of absolute positioning (with the latter you'll end up with 'empty' space between menu and submenu, causing mouseout):
http://jsfiddle.net/BAzx7/
EDIT: And I added position:relative; to ul li, and a lower z-index to ul li ul, otherwise the submenu would be over the main menu - and disable it...
http://jsfiddle.net/BAzx7/1/
I've also fixed this with hoverIntent on one of my drop downs. Was an exclusive IE bug at the time but was a easy fix.
http://cherne.net/brian/resources/jquery.hoverIntent.html
This is how my function looked.
$('.main-nav > ul > li').hoverIntent({
timeout: 300,
over: function () {
$(this).addClass('hover')
},
timeout: 300,
out: function () {
$(this).removeClass('hover')
}
});
My markup was in the same structure as the son of sucker fish menu.