Second level submenu CSS - css

I was hoping if you can help me with my little problem. I am just updating one of my developers style sheets. I am a beginner in CSS so I am having difficulties adding the second level submenu in it.
Here's the link DEMO PAGE
This is my HTML
<div id="sidebar"><i class="icon icon-home"> </i>Dashboard<ul style="display: block;">
<li class="active"><i class="icon icon-home"></i> <span>Dashboard</span> </li>
<li> <i class="icon icon-signal"></i> <span>Charts & graphs</span> </li>
<li><i class="icon icon-th"></i> <span>Tables</span></li>
<li><i class="icon icon-fullscreen"></i> <span>Full width</span></li>
<li class="submenu"> <i class="icon icon-th-list"></i> <span>API</span> <span class="label label-important">4</span>
<ul>
<li>
boom
<ul>
</ul>
</li>
<li>% of National Roads Paved</li>
<li>Process</li>
<li>Regional Profiles</li>
</ul>
</li>
</ul>
</div>
and this is my CSS
/* Top user navigation */
#sidebar{ width:100%; background:#252125; position:absolute; clear:both; top:62px;}
#sidebar > ul{ margin:0px; padding:0px; width:100%; display:block; z-index:999;}
/*Border right sidebar */
#sidebar > ul > li { list-style-type:none; float:left; display:block; margin:0px; border-right:1px solid #464652; position:relative; padding:10px; cursor:pointer}
/*Border right */
#sidebar > ul > li a{ padding:12px 0;}
#sidebar > ul > li:hover ul { display:block;}
/*#sidebar > ul > li:hover { background-color:#41bedd;} */
/*On hover menu */
#sidebar > ul > li:hover { background-color:#464652;}
/*On hover menu */
#sidebar > ul > li:hover a{ background:none;}
/*Modules color */
#sidebar > ul li ul { margin:0px; padding:0px; display:none; z-index:999; position:absolute; left:0px; top:40px; background:#464652; min-width:200px;}
/*Modules color */
#sidebar > ul li ul li { list-style-type:none; margin:0px; font-size:12px;line-height:30px; }
#sidebar > ul li ul li a { display:block; padding:5px 10px; color:#fff; text-decoration:none; font-weight:bold; }
/*Modules color on hover */
#sidebar > ul li ul li:hover a{ background-color:#5A5A69;}
/*Modules color on hover*/
#sidebar > ul li span { cursor:pointer; margin:0px 2px 0 5px; font-weight:bold; color:#fff; font-size:11px; }
#sidebar > ul li a i{ background-image: url("../img/glyphicons-halflings-white.png"); margin-top:4px; vertical-align: top;}
I know this post has been posted from different threads. I really cant understand them. Hope you understand. Thanks in advance.

First of all, in your sample HTML, you don't have any lis in your tertiary level. Put some in there.
As for your CSS, it's presently set up to handle the showing and hiding of UL's below the top level one on hover. We need to get more specific so that it excludes the 3rd level--as well as then get more specific to and add a second level hover style.
Where you have this:
#sidebar > ul > li:hover ul { display:block;}
Change it to this:
#sidebar > ul > li:hover > ul { display:block;}
The first will show ALL child ULs of the LI on hover. The latter will show only the direct child of the LI on hover.
Now we need to add a trigger for the 3rd level:
#sidebar > ul > li > ul > li:hover > ul { display:block; top: 0; left: 200px}
While we're at it, we included a new set of positioning so that it appears to the right of the current hover rather than below (which would cover up the second level navigation.
Working example: http://jsfiddle.net/wS9t3/

Related

CSS Dropdown Menu disappearing

I have created a side drop down menu and everything is positioned however every time I go to move my cursor onto the menu it disappears, I have a feeling this is something to do with the :hover I have used but I cannot seem to get it stop disappearing Can anyone help?
my html is :
<div class="navBar">
<ul>
<li class="navText">L1</li>
<li class="navText dropdownTrigger">L2</li>
<ul class="dropdown">
<li>L6</li>
<li>L7</li>
<li>L8</li>
<li>L9</li>
<li>L10</li>
</ul>
<li class="navText">L3</li>
<li class="navText">L4</li>
<li class="navText">L5</li>
</ul>
</div>
my css is :
* {
padding:0px;
margin:0px;
}
body {
background-color:rgba(17,17,17,1);
background-size:cover;
}
.navBar {
position:fixed;
width:70px;
height:100%;
padding-top:100px;
background-color:rgba(255,255,255,0.5);
text-align:center;
}
.navBar > ul > li,
.navBar > ul > li > a {
margin-top:70px;
text-decoration:none;
display:block;
color:black;
font-family:"Constantia";
font-size:30px;
}
.navBar > ul > ul > li,
.navBar > ul > ul > li > a {
display:block;
list-style-type:none;
text-decoration:none;
color:black;
font-family:"Duan Penh";
font-size:24px;
}
.navBar a:hover,
.navBar li:hover {
background-color:rgba(0,0,0,0.5);
color:white;
font-weight:bold;
}
.navBar > ul > ul {
background-color:rgba(255,255,255,0.5);
width:200px;
height:auto;
margin-left:70px;
margin-top:-35px;
position:absolute;
display:none;
}
.dropdownTrigger:hover ~ .dropdown {
display:block;
}
Try this
.dropdownTrigger:hover ~ .dropdown, .dropdown:hover {
display:block;
}
jsFiddle : https://jsfiddle.net/ojf32faz/

menu's go down when zoomed-out in browser

I am doing a website project on asp.net 3.5. When i Zoom-out the interface on web-browser my menu bar's Contact tab goes below also the places to visit tab's line "visit" comes below. How can I overcome this problem?
HTML
<div id="nav">
<ul>
<li>Home</li>
<li>About us</li>
<li>Reservation
<ul>
<li>Room</li>
<li>Membership</li>
<li>Events</li>
</ul>
</li>
<li>Places to visit</li>
<li>Travel</li>
<li>Packages</li>
<li>Gallery</li>
<li>Contact us</li>
</ul>
</div>
CSS
#nav { clear:both; margin:0;
padding:0;width:900px; height:30px;}
#nav ul { margin:0; padding:0; line-height:30px; }
#nav li { margin:0; padding:0; list-style:none; float:left;
position:relative;
background-color:#0066CC/*#1B6187*/;}
#nav ul li a { text-align:center;
font-family:Georgia;
text-decoration:none;
font-size:14px;
height:30px; display:block;
color:#FFF; width:110.5px;
border:1px solid #006363;
}
#nav ul ul { position:absolute; visibility:hidden; top:32px;}
#nav ul li:hover ul {visibility:visible;}
#nav li:hover { background:#09F;}
#nav ul li:hover ul li a:hover {background-color:#09F;
color:#4EE6DB;}
#nav ul li ul li { background-color:#0066CC/*#1B6187*/;}
#nav a:hover { color:#000;}
.clearFloat {clear:both;}
This happens because the text doesn't scale well when zooming: it stays bigger than you'd expect. The text forces the surrounding li's and a's to get bigger than you'd like.
I recently fixed the same issue by fixing the width of each li (eg: width: 30px). The text will still be bigger than you'd like, but if you use enough padding it has enough space to grow.
What you could also try is position the last li absolutely top top:0, right:0, this will get ugly as the last li will lay over the one before the last

CSS Drop Down Navigation, 3rd level issue

I'm trying to get a 3rd level of flyout/dropdown on this CSS navigation menu. The second level works great, only shows when you're hovering over the right top level link. However, the 3rd level shows when you hover over the TOP level also. It should be hidden until you hover over the right dropdown link and then flyout to the right. I have the position correct, but I need it to hide until the right link is hovered on.
Here's the site I'm working on: http://174.37.160.21 (the 3rd tier is under Products).
Here's my CSS for the whole menu. I'm sure it's something really easy to spot but I've tried all that I can think of. I'm not a CSS wizard or anything.
.menu { height:32px; position:relative; z-index:100; }
.menu ul {padding:0;margin:0;list-style-type:none;}
.menu li {float:left;width:auto; padding-left:6px; padding-right:6px; position:relative;}
.menu ul li a { font-size:13px; }
.menu ul li ul li a { font-size:13px; }
.menu a, .menu a:visited {display:block; font-size:15px; text-decoration:none; color:#454545; height:30px; border:1px; padding-left:10px;}
.menu ul ul { visibility:hidden; position:absolute; height:0; top:20px; left:0; width:150px; }
.menu ul ul li { background:#272727; width:150px; text-align:left; padding-top:5px; padding-bottom:5px; }
.menu ul ul li:hover { background:#454545; }
.menu ul ul ul { visibility:hidden; position:absolute; height:0; top:0; left:150px; width:150px; }
.menu ul ul ul li { background:#272727; width:150px; text-align:left; padding-top:5px; padding-bottom:5px; }
.menu ul ul ul li:hover { background:#454545; }
.menu table {position:absolute; top:0; left:0; border-collapse:collapse;} /* style the table so that it takes no ppart in the layout - required for IE to work */
.menu ul ul a, .menu ul ul a:visited, .menu ul ul ul a, .menu ul ul ul a:visited { color:#fff; height:auto;}
.menu a:hover, .menu ul ul li:hover { }
.menu :hover > a, .menu ul ul :hover > a, .menu ul ul ul :hover > a {}
.menu ul li:hover ul, .menu ul a:hover ul, .menu ul ul li:hover ul { visibility:visible; }
Here's is my HTML Code:
<ul>
<li>Home
<li>About Us</li>
<li>Services
<ul>
<li>Residential</li>
<li>Commerical</li>
<li>Emergency</li>
<li>Maintenance</li>
</ul>
</li>
<li>Products
<ul>
<li>Garage Doors
<ul>
<li>Residential Garage Doors</li>
<li>Commercial Garage Doors</li>
</ul>
</li>
<li>Openers & Operators</li>
</ul>
</li>
<li>Online Store
<ul>
<li>Replacement Remotes</li>
<li>Keyless Entry</li>
<li>Gears & Sprocket Parts</li>
<li>Safety Beams</li>
<li>Lube & Grease</li>
</ul>
</li>
<li>Ask a Pro
<ul>
<li>Submit a Question</li>
<li>Newsletter</li>
<li>FAQ's</li>
<li>News</li>
<li>Seasonal Tips</li>
</ul>
</li>
</ul>
This is the part that makes the submenu visible:
.menu ul li:hover ul,
.menu ul a:hover ul,
.menu ul ul li:hover ul { visibility:visible; }
Now, I'm not sure what your markup is (I can only guess seeing .menu table and a:hover ul...), but with a standard list based markup, this part is too greedy:
.menu ul li:hover ul
This selects all ul elements that are in the li:hover all the way down the line, up to the very last one. I think you want to select only the direct descendant:
.menu ul li:hover > ul
All I changed was adding the > character. Demo: http://jsfiddle.net/dgUFw/
EDIT: Updated demo with the HTML you just posted: http://jsfiddle.net/dgUFw/1/
The .menu element was missing from your post, so I wrapped the whole thing in a <div class="menu"> and it seems to work fine.

css sub-menu vanishes before I can click, need help to identify bug(s)

I have a horizontal menu coded in html and css only, this menu has sub-menu and some sub-menu has sub-menu of their own.
It works fine with the first level sub-menu only, but when I insert some sub-menu for any individual sub-menu, they still show up. But I can not reach to click them, they vanishes as my cursor moves. A demo can be found here : http://example.bojroninad.net/pages/menu_demo1.html
However, I was able to watch some steady behavior of this menu sometimes, but most of the time they vanishes before I reach to them.
Here is my html code(pardon me for bad structured code):
`<html>
<link rel="stylesheet" href="menu1_css.css" media="screen" type="text/css">
<div id="menu1">
<ul>
<li>Home</li>
<li>About
<ul>
<li>History</li>
<li>Team</li>
<li>Offices</li>
</ul>
</li>
<li>Services
<ul>
<li>Web Design </li>
<li>Internet Marketing</li>
<li>Hosting </li>
<li>Domain Names
<ul>
<li>.ORG</li>
<li>.COM</li>
<li>.NET</li>
</ul>
</li>
<li>Broadband </li>
</ul>
</li>
<li>Contact Us
<ul>
<li>United Kingdom</li>
<li>France </li>
<li>USA </li>
<li>Australia </li>
</ul>
</li>
</ul>
</div>
</html>`
and my css code goes here:
#menu1 {
background-color:#ccc;
width:100%;
height:30px;
}
#menu1 ul{
padding:0px;
margin:0px;
}
#menu1 ul li
{
list-style:none;
display:inline;
margin-left:10px;
float:left;
height:30px;
position:relative;
}
#menu1 ul li a{
text-decoration:none;
font-weight:bold;
font-family:Bitstream Cyberbit,Garamond, Minion Web, ITC Stone Serif, MS Georgia;
color:green;
}
#menu1 li a:hover{
text-decoration:underline;
}
#menu1 li ul {
display:none;
margin:0px;
padding:0px;
position:absolute;
left:0px;
top:20px;
width:120px;
background-color:#999;
}
#menu1 li:hover ul{
display:block;
width:160px;
}
#menu1 li li {
display:list-item;
list-style:none;
}
/* second level sub menu */
#menu1 li li ul {
padding:0px;
margin-left:150px;
background-color:white;
top:0px;
position:relative;
}
#menu1 li li li{
display:none;
list-style:none;
position:absolute;
width:120px;
background-color:red;
}
#menu1 li li:hover li{
display:block;
width:100px;
position:relative;
margin-left:0px;
float:left;
height:30px;
}
#menu1 ul li li li a{
text-decoration:none;
font-weight:bold;
font-family:Bitstream Cyberbit,Garamond, Minion Web, ITC Stone Serif, MS Georgia;
color:yellow;
}
#menu1 li li li a:hover{
text-decoration:underline;
}
The problem is that your second and third level list elements are also floated left, making them smaller than the menu itself.
You can solve it by setting:
#menu1 li li {
float: none; /* line 50 */
}
#menu1 li li ul {
position: absolute; /* line 57, is now relative, to avoid growth of li li */
}
As far as I can see, the menu works fine - except that the second-level menu is positioned a bit too low
Usability would also be much better if you changed background color on li:hover + cursor:pointer - so you can see which button in the menu is active (and the user gets a visual feedback when he hovers out).

Why does this text pop to the left in Webkit?

Maybe somebody has seen this before? When you hover over the "First List" and "Second List" text, the text pops a couple pixels to the left. This only happens in Webkit browsers. Tested in Chrome on Linux and Mac, Safari on Mac, and Android browser. Here's the code. I also made a fiddle: http://jsfiddle.net/XzVLt
#navigation {
line-height:30px;
height:30px;
clear:left;
text-align:left;
position:relative;
}
#navigation li {
padding:0 5px;
margin-left:-1px;
width:100px;
text-align:center;
float:left;
display:inline;
}
#navigation ul ul {
display:block;
position:absolute;
}
#navigation li ul {
margin-left:-5px;
padding-right:10px;
}
#navigation li ul li {
margin-right:-2px;
text-align:left;
line-height:15px;
padding:5px;
clear:both;
width:100%;
}
#navigation ul li {
list-style:none;
}
#navigation ul li {
float:left;
list-style:none;
}
#navigation li ul {
display:none;
}
#navigation li:hover ul {
display:block;
}
#navigation a {
font-size: 0.8em;
}
#navigation li li a {
display:block;
margin-left:10px;
text-indent:-10px;
}
​
<div id="navigation">
<ul>
<li>
First list
<ul>
<li>Item</li>
<li>Item</li>
<li>Item</li>
</ul>
</li>
<li>
Second list
<ul>
<li>Item</li>
<li>Item</li>
<li>Item</li>
</ul>
</li>
</ul>
</div>​
I'm guessing that it has something to do with your margins and padding that comes into play as soon as you change the drop-down from display:none to display:block
I use the suckerfish method for drop-downs; you can easily implement this in your method as well. Just change how you phase in the drop-down content as follows:
Replace ...
#navigation li ul {
display:none;
}
#navigation li:hover ul {
display:block;
}
... with ...
#navigation li ul {
position:absolute;
left:-999em;
}
#navigation li:hover ul {
left:auto;
}
Quick tests in Firefox and Safari - it works just fine ... you'll need some JS to create an element to replace the li:hover pseudo or it won't work in IE.
Read more about the method here http://htmldog.com/articles/suckerfish/dropdowns/

Resources