Nested Drop Down Menu Alignment - html

I've spent a few days already finding a way to evenly space variable sized menu items across a fixed width horizontal bar, and finally found a jquery solution detailed here. The problem I now have is that my nested drop-down menus appear quite differently in different browsers and I very simply need them to drop down from their respective li anchors properly.
This is the site in question
So far it looks ok on firefox. In Internet Explorer the dorp down menu's are pushed over to the right, and in Safari they are pushed over to the left. I've tried a number of things, but I think it's beyond me at the moment.
here's the relevant HTML & CSS, although you can view source on the site too:
<nav>
<ul id="main-nav">
<li>Home</li>
<li>Products
<ul>
<li>Wood Wool</li>
<li>Wood Wool Bales</li>
<li>Wood Wool Rope</li>
<li>Coloured Wood Wool</li>
</ul>
</li>
<li>Applications
<ul>
<li>Hamper Packaging</li>
<li>Wine & Champagne</li>
<li>General Gifts</li>
<li>Soaps & Cosmetics</li>
<li>Shellfish Packaging</li>
<li>Stable Bedding</li>
<li>Industrial</li>
<li>Pesticide Alternative</li>
</ul>
</li>
<li>What's Wood Wool?</li>
<li>The Eco Bit</li>
<li>Get in touch</li>
<li>Blog</li>
</ul>
</nav>
/* NAVIGATION BAR */
header nav{
background-image: url(../_images/nav-bar-bg.png);
height: 48px;
width: 960px;
position: absolute;
top: 96px;
}
header nav #main-nav{
width:900px;
margin-left:30px;
}
header nav ul li {
display:block;
float: left;
}
header nav ul li a {
display:inline-block;
height:48px;
line-height:48px;
text-decoration: none;
color: white;
font-weight:normal;
font-size:16px;
}
header nav ul li a:hover {
color: #09b497;
text-shadow:2px 2px 2px #000;
}
/* NESTED MENU OPTIONS */
header nav ul li ul {
position:absolute;
float: left;
visibility: hidden;
top:40px;
height:auto;
border:2px solid #0a7c6c;
background-color:#FFF;
-webkit-border-radius: 6px;
-moz-border-radius: 6px;
border-radius: 6px;
-moz-box-shadow: 0 0 10px #000;
-webkit-box-shadow: 0 0 10px #000;
box-shadow: 0 0 10px #000;
}
header nav ul li:hover ul {
visibility: visible;
}
header nav ul li ul li {
display:block;
height:30px;
float:left;
clear:left;
}
header nav ul ul li a{
padding: 0 12px;
line-height:30px;
text-align:left;
font-size:14px;
color:#0a7c6c;
}
header nav ul ul li a:hover{
color: #09b497;
text-shadow:none;
}

Add position:relative to your header nav ul li. Your header nav ul li ul has it's position set to absolute so it should be absolute with respect to it's parent.
Forgot to add, you'll also need to add a width to the header nav ul li ul or atleast a min-width.

Related

Text not horizontally centre in nav bar / How to make a <br> half the size/ Too much space between nav bar text

Here I have my website: http://gyazo.com/56e069ebf8b5bd61ee30523886180b88
There are a number of issues with the nav bar.
You can see that the text or nav bar is not horizontally centered, as indicated by the hover (which is equal on top and bottom)
There is to much space in between the text, (and this spacing is the only way I've found works without the text moving around when highlighting or hovering.
The <.br> spacing on the drop down menu is too spaced apart.
So for 1. is there a way I can make the text or the nav bar (not sure what is the cause) centre so the hover looks more equal (horizontally)
For 2. Is there a way I can close the gap between the text, while still keeping the same padding settings, and so it doesn't move the text around when I use the hover function.
And 3. Is there a way to make the <.br> have half the space it currently uses
I've also added a jsfiddle if that helps: http://jsfiddle.net/d1a5eshs/
HTML code for the nav bar:
<!--TOP NAV BAR SECTION-->
<div id="nav_bar">
<ul>
<li>HOME
</li>
<li>STATUS
</li>
<li>INFO
</li>
<li>GAMEMODES
<ul>
<li>SURVIVAL
</li>
<li><br>PURE-PVP
</li>
<li><br>GAMESWORLD
</li>
</ul>
</li>
<li>RULES
</li>
<li>VOTE
</li>
<li>CONTACT
</li>
</ul>
</div>
And the CSS for the nav bar:
/*TOP NAV BAR SECTION*/
#nav_bar {
background-color: #a22b2f;
padding:1px;
box-shadow: 0px 2px 10px;
height:45px;
}
#nav_bar ul li {
display: inline-block;
}
#nav_bar ul li a {
color: white;
text-decoration:none;
font-weight:bold;
font-size:15px;
margin-left:10px;
padding-bottom:13px;
padding-top:17px;
padding-left:10px;
padding-right:10px;
margin-bottom:30px;
}
#nav_bar ul li ul {
display: none;
}
#nav_bar>ul>li>a:hover {
background:#8c1b1f;
padding-bottom:13px;
padding-top:13px;
padding-left:10px;
padding-right:10px;
}
#nav_bar>ul>li>ul>li>a:hover {
background:#c9c9c9;
padding-bottom:5px;
padding-top:5px;
padding-left:5px;
padding-right:5px;
}
#nav_bar ul li:hover ul {
display: block;
position: absolute;
padding: 0px;
background: #e2e2e2;
padding-top:10px;
padding-bottom:10px;
padding-left:0px;
padding-right:10px;
border: 1px solid black;
border-radius:5px;
}
#nav_bar ul li:hover ul li {
display: block;
}
#nav_bar ul li:hover ul li a {
color: black;
font-size:12px;
font-weight:bol;
margin-left:-20px;
padding-bottom:5px;
padding-top:5px;
padding-left:5px;
padding-right:5px;
}
you dont have to use the in your inner list. adjust line-height to get desired result.
http://www.jsfiddle.net/9058vefk
#nav_bar ul li:hover ul {
display: block;
position: absolute;
padding: 0px;
background: #e2e2e2;
padding-top:10px;
padding-bottom:10px;
padding-left:10px;
padding-right:10px;
border: 1px solid black;
border-radius:5px;
line-height:1.5em; /* added this- you can change it th=o what you want */
height:5em;
}
as far as centering the main ul li , divide the entire div (nav_bar) into 7 equal smaller divs and apply that space to each nav item.

css styling of drop down menu

I am trying to style my drop down menu so it would look like on my picture:
![drop down menu]()
So far I got this:
`<nav>
<ul id="home">
<li>HOME</li>
</ul>
<ul id="about">
<li>ABOUT</li>
</ul>
<ul id="business">
<li>BUSINESS GROWTH
<ul class="sub-menu">
<li>BUSINESS GROWTH </li>
<li>FAQs</li>
<li>FEES & SCHEDULING</li>
<li>QUESTIONNAIRE</li>
</ul>
</li>
</ul>
`
#business,
#home,
#about
{
list-style-type: none;
}
#business li{
position:relative;
background-color: #004473;
display:inline-block;
width: 180px;
}
#business li a {
color: #fff;
text-decoration: none;
display:inline-block;
}
#business li ul {
position: absolute;
left: -9999px;
background-color: grey;
margin:0;
padding:0;
list-style-type: none;
width: auto;
}
#business li:hover ul {
left: 0px;
display:inline-block;
}
#business li ul li {
background-color: #004473;
width: 180px;
display:inline-block;
margin:0;
padding:0;
}
#business li ul li a {
color:#fff;
text-decoration: none;
font-style: italic;
}
#business li ul li a:hover {
text-decoration:underline;
}
main issues:
display menu horizontally (home about business growth should be on the same horizontal line)
arrow shape of main menu item
a gap between main menu items and the sub-items
http://codepen.io/anon/pen/oDzbH
Could you please help? Very appreciated.
display menu horizontally (home about business growth should be on the same horizontal line)
add this in css
nav,nav ul{
display:inline-block;
}
arrow shape of main menu item
i assume you want it on hover
ul li > a:hover{
display:block;
background:#fff url(images/arrow.png) no-repeat center bottom;
}
a gap between main menu items and the sub-items
add this in css
ul.sub-menu{
margin-top:10px; /* or whatever suits your layout*/
}

Copy table tag formatting to ul & li tags

add List Image and Background Image to <li> items...
CSS Code :-
.sidebarmenu ul{
margin: 0;
padding: 0;
list-style-type: disc;
font:bold 14px Verdana;
width: 180px; /* Main Menu Item widths */
border: 2px solid skyblue;
}
.sidebarmenu ul li{
position: relative;
}
/* Top level menu links style */
.sidebarmenu ul li a{
display: list-item;
overflow: auto; /*force hasLayout in IE7 */
color: red;
text-decoration: none;
padding: 6px;
border-bottom: 1px solid #778;
border-right: 1px solid #778;
}
.sidebarmenu ul li a:link, .sidebarmenu ul li a:visited, .sidebarmenu ul li a:active{
background-color: lightblue;/*background of tabs (default state)#012D58*/
}
.sidebarmenu ul li a:visited{
color: black;
}
.sidebarmenu ul li a:hover{
background-color: lightskyblue;
}
/*Sub level menu items */
.sidebarmenu ul li ul{
position: absolute;
width: 170px; /*Sub Menu Items width */
top: 0;
visibility: hidden;
}
.sidebarmenu a.subfolderstyle{
background: url(images/right.gif) no-repeat 97% 50%;
}
HTML FORM:-
<body>
<div class="sidebarmenu">
<ul id="sidebarmenu1">
<li>Add Location
<ul>
<li>Add Flat</li>
<li>Add Area</li>
</ul>
</li>
<li>Log Out</li>
</ul>
</div>
</body>
first of all... your table structure and your ul-li structure is different:
table cells are all on same level // li levels are different
link names are different
i guess what you want to do is:
set the "images/user_manager.jpg" Image to the list-style-image
as we dont see the images and dont know what they are looking like i
believe you want to set the "images/bg.jpg" Image as the
background-image of the li-tags
in situations like that a screenshot or link would be nice.

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.

IE 7 ul li nesting and positioning - the top end does not match up

Here's the link to the page:
http://themes.brixwork.com/altamont/
The positioning of the tags under the ul#menu appears to be skewed on IE7. I have put borders on the UL (#f00) and LI (#0f0) items to clarify.
IN Firefox, the LI items nest properly to the top of the UL, however on IE the LI nests to the top of the div#menubar rather than the ul#menu under it.
The DOM tree is like this:
<div id="menubar" class="grid_16 alpha omega">
<ul id="menu">
<li style="margin-left:0px;">home</li>
<li>about me</li>
<li>featured listings
<ul class="submenu">
<li>
on a map
</li>
</ul>
</li>
<li>
MLS® search
</li>
<li>
resources
<ul class="submenu">
<li>
for buyers
</li>
<li>
for sellers
</li>
<li>
pre-sale / assignment
</li>
<li>
useful links
</li>
</ul>
</li>
<li>
blog
</li>
<li>
contact me
</li>
</ul>
</div>
Pretty standard div>ul>li menu structure, with optional submenus under each as a ul.submenu>li structure.
I tried putting a "float:left;" to the #menu li node, and that did solve the positioning; however then I don't have a nice centre aligned menu - everything goes to the left on the menu.
Here's the current css revolving around this (note that I'm using 960 grid, and also the reset.css and text.css file that comes with it).
#menubar {
height:40px;
text-align: center;
}
#menu {
margin:10px auto;
padding:0px;
z-index: 20;
width: auto;
display: block;
list-style:none;
white-space: nowrap;
position: relative;
border: 1px solid #f00;
}
#menu li {
display:inline;
margin-left:40px;
margin-right:0px;
margin-top:10px;
margin-bottom:0px;
padding:0px 0px 0px 0px;
list-style:none;
z-index: 25;
position: relative !important;
border: 1px solid #0f0;
}
#menu li a:link, #menu li a:visited {
color:#fff;
text-decoration:none;
font-size:12px;
padding: 10px 0px;
text-transform: uppercase;
}
#menu li a:hover {
color:#ddd;
}
#menu li a:active {
position:relative;
top:1px;
color:#fff;
}
.submenu {
position:absolute;
left: -9999px;
display: block;
background-color:#906117;
padding:0px 0px 0px 0px;
top:0px;
z-index:30;
}
#menu li:hover .submenu {
left: 0px;
}
.submenu li {
text-align: left !important;
margin:0px !important;
padding: 3px 0px 5px 0px !important;
clear: both;
float: left;
position:relative;
overflow: hidden;
z-index: 35;
width: 100% !important;
}
.submenu li:hover {
background-color: #f79c10;
}
.submenu li a:link, .submenu li a:visited {
color:#fff !important;
font-size:12px !important;
padding: 0px !important;
margin: 0px !important;
white-space:nowrap;
display: block;
width: 100%;
padding:3px 10px 5px 10px !important;
z-index: 40;
}
.submenu li a:hover, .submenu li a:active {
color:#fff !important;
}
IE7 ignores margins when ul elements have a relative position. You can fix this by removing the margin in your ul#menu styles and add that value back in the parent div#menubar.
This will give you the same layout result, but will resolve the IE7 margin/relative bug.