Center submenu under parent list-items with variable widths - css

Sorry I can't put this code live anywhere at the moment but hopefully the screenshots will help. I'm trying to precisely center a sub-menu ul beneath li's of variable width, like so:
Here's a truncated version of my layout:
<div class="nav">
<ul class="menu">
<li>
Home
</li>
<li>
Kids
<ul class="sub-menu">
<li>Sub-item 1</li>
<li>Sub-item 2</li>
</ul>
</li>
<li>
Students
</li>
<li>
Adults
<ul class="sub-menu">
<li>Sub-item 1</li>
<li>Sub-item 2</li>
</ul
</li>
</ul>
</div>
I have the arrow on the sub-menu working and aligned to the center of the sub-menu ul, but the sub-menu itself isn't aligning correctly with its parent li, as you can see here. The sub-menus showing are for the "kids" li and the "adults" li, as above:
This is the relevant code, I believe. Any help is MUCH appreciated!
.menu li {
display:inline-block;
list-style-type: none;
position: relative;
}
.menu li a {
background:url("_/images/nav-cross-home.png") 50% 5px no-repeat;
display:inline-block;
padding:30px 5px 2px;
text-transform: uppercase;
text-decoration: none;
color:#000;
font-family:proxima-nova, Arial, Helvetica, sans-serif;
font-weight:700;
font-size:.9em;
margin: 0 auto 10px;
}
.nav ul ul {
display: block;
position: absolute;
margin: 10px 0px 0px -15px;
top: 3.333em;
left: -125%;
width: 170px;
z-index: 99999;
border:2px solid #929292;
}
.nav ul.menu ul.sub-menu a {
background: #fff !important;
border-bottom: 1px solid #e5e5e5;
color: #444;
font-size: .9em;
text-transform: none;
height: auto;
line-height: 1.4em;
padding: 10px 10px;
width: 150px;
margin-bottom:0px;
}

Here you go.
.nav ul ul {
margin-left:-87px;
left: 50%;
}
So left 50% gets the ul to the mid point of the parent li, and then negative left margin half of the total width (including borders = 174).
Update: here's an example. http://jsfiddle.net/mcpatriot/jzWcD/

Related

Responsive menu not showing all my dropdown menus in mobile version

If you reduce my test page here: http://www.linestop.com/Linestop2015/index.php
To display the mobile dropdown menu you will notice that not all my submenu items are displaying. How can I fix this? Can you help me?
Here is my CSS
#navigation { padding:0 21px; margin-bottom: 0; }
.sf-menu{
margin-bottom: 0;
}
.top-nav,.sf-menu li{
background: transparent;
}
.sf-arrows .sf-with-ul:after{
border-top-color: #ff9000;
}
.sf-menu ul li,.sf-menu ul ul li,.sf-menu ul ul ul li {
background: #fff;
}
.sf-menu li:hover, .sf-menu li.sfHover {
background: #ff9000;
}
.sf-menu a{
color: #070707;
border:none;
font-family: 'Open Sans', sans-serif;
text-transform: uppercase;
font-size: 1.2em;
padding-left: 2em;
padding-right: 2em;
}
.small-top-menu{
display: none
}
.small-top-menu select{
padding: 5px;
background: #68ceef;
font-family: 'Open Sans', sans-serif;
text-transform: uppercase;
border:5px solid #fff;
margin: 10px 0;
}
.small-top-menu select option{
padding: 10px;
}
#navigation ul li a { color: #4a4a4a; padding: 0 7px; display:block; height: 21px; line-height: 21px; border: 2px solid transparent; border-radius: 3px; -moz-border-radius: 3px; -webkit-border-radius: 3px; -o-border-radius: 3px; width:100% }
#navigation ul li.active a,
#navigation ul li a:hover { border: 2px solid #029cdb; background: url(images/nav-btn.png) repeat-x 0 0; color:#fff; text-decoration: none; }
#navigation a.nav-btn { display:none; }
Here is my mobile menu css
#navigation { position:relative; z-index: 100; padding:0 0px; margin:0 10px; }
#navigation a.nav-btn { margin-bottom: 15px; text-decoration: none; padding:0 36px 0 10px; line-height:30px; display:block; background: url(images/navigation.png) repeat-x 0 0; height: 30px; position: relative; }
#navigation a.nav-btn span { background: url(images/dd-nav-arrs.png) no-repeat 0 bottom; width: 20px; height: 15px; position:absolute; top: 8px; right: 12px; }
#navigation a.nav-btn.active span { background-position:0 0; }
#navigation ul { display:none; position: absolute; top: 30px; left: 0; width: 100%; }
#navigation ul li { float:none; height: 30px; border-top: 1px solid #fff; display:block; padding:0 0 0 0; background: url(images/navigation.png) repeat-x 0 0; }
#navigation ul li a { border: 0; line-height:30px; float:none; height: 30px; display: block; font-size: 14px; padding-left: 20px; padding-right: 20px; width:100%; border-radius: 0px; -moz-border-radius: 0px; -webkit-border-radius: 0px; -o-border-radius: 0px; box-sizing:border-box; -moz-box-sizing:border-box; -webkit-box-sizing:border-box; }
#navigation ul li a:hover { background-image:url(images/blue-btn.png); border:0; }
#navigation ul li.active span { background: transparent; border:0; }
#navigation ul li.first { display:block; }
Here is my html code
<nav id="navigation"> HOME<span></span>
<section>
<ul class="sf-menu large-12">
<li class="active">Home</li>
<li class="has-dropdown">Services
<ul class="dropdown">
<li class="has-dropdown">Hottap Services
<ul class="dropdown">
<li>Hottap Free Quote</li>
</ul>
</li>
<li>Linestop Services
<ul class="dropdown">
<li>Linestop Free Quote</li>
</ul></li>
<li>Valve Installations Services
<ul class="dropdown">
<li>Valve Install Free Quote</li>
</ul></li>
<li>Pipeline Bypass Services
<ul class="dropdown">
<li>Pipe Bypass Free Quote</li>
</ul></li>
</ul>
</li>
<li class="has-dropdown">Line Stop Equipment
<ul class="dropdown">
<li class="has-dropdown">Hottap Machines
<ul class="dropdown">
<li>Small Machines</li>
<li>Large Machines</li>
</ul>
</li>
<li>Linestop Machines
<ul class="dropdown">
<li>QualTech QT Linestop Machines</li>
<li>IFT Soft Stop 100</li>
<li>IFT Top Pivot Stop 1000</li>
<li>IFT Folding Heads</li>
</ul></li>
<li>Hottap / Linestop Fittings
<ul class="dropdown">
<li>IFT 499 Fittings Copper, Steel & PVC</li>
<li>IFT Mechanical Joint Fittings</li>
<li>IFT Stainless Steel Hottap Linestop Fittings</li>
<li>IFT On-Size Folder Weld Type Fittings</li>
<li>IFT 400 Series Fittings CMLC</li>
<li>IFT 500 Series Fittings CMLC</li>
<li>AWWA - Fittings</li>
<li>Flanged Steel Knife Gate Valves</li>
<li>Completion Plug Assemblies</li>
</ul></li>
<li>All 2.5"-54.6" Linestop™ Cups</li>
</ul>
</li>
<li class="has-dropdown">About us
<ul class="dropdown">
<li>Contact Us</li>
<li>Customers</li>
<li>Location</li>
<li>Job Application</li>
<li>Online Flip Catalog</li>
<li>Facebook Fan Page</li>
</ul>
</li>
<li>Featured Jobs</li>
</ul>
</section>
<div class="cl"> </div>
</nav>
Thanks, Jesse
Look at the #navigation ul styling, the position: absolute; property should only be applied to the first UL ('.sf-menu'). Also check the .sf-menu ul styling, it should have an absolute position. And remove the height from #navigation ul li, because some li items have sub menus but you can't see them because the height is only 30px.
I figured out the answer to my issue. trying to make the menu too complex there were no easy fixes. So i had to go back to the original code and just use the mobile menu for the main navigation menu. Seems to work fine... Thanks for for the help!

Css Vertical Menu Fly Out

The submenu of the vertical dropdown portion of my .css-driven menu has an issue. In the jsfiddle example, high lighting 'Bedroom Furniture' under 'Products' displays 'Bunk Beds'. While Bunk Beds' is being displayed, the menu option below (Home Office) isn't selectable (actually, it CAN be selected if the mouse is moved to the far right of Home Office). I've exhausted all of my ideas and any help would be appreciated.
I think the issue is in the 'second level vertical drop down' section of the CSS (CSS snippet...please see jsfiddle example)
.rmenu li ul li:hover ul li a {
/*padding: 0px 0px 0px 33px;*/
padding: 0px 0px 0px 5px;
background: #e8dec7;
/*background color for submenu hovered text*/
color: #51db29;
/* this is the color of the sub-sub menu text. I made the color (#51db29) 'unusual' as an example. Should be changed to something less jarring (of course) */
word-wrap: break-word;
min-width:100px;
position: relative;
left: 175px;
top: -35px;
/* display 3rd level to the right*/
}
/* -- Appearance of second vertical dropdown menu hovered (submenu of first level vertical menu) -- */
.rmenu li ul li:hover ul li:hover a {
color: #000000;
/*hovered text color*/
min-width:100px;
}
/* ----
see the js fiddle : http://jsfiddle.net/mf3y6Lj6/1/
try this :
<div id="header">
<div id="nav">
<ul>
<li>
Menu1
<ul>
<li>submenu
<ul>
<li>sub sub menu</li>
<li>sub sub menu</li>
<li>sub sub menu</li>
<li>sub sub menu</li>
</ul>
</li>
<li>submenu</li>
<li>submenu</li>
<li>submenu</li>
<li>submenu</li>
</ul>
</li>
<li>
Menu2
</li>
<li>
Menu3
<ul>
<li>submenu</li>
<li>submenu</li>
<li>submenu
<ul>
<li>sub sub menu</li>
<li>sub sub menu</li>
<li>sub sub menu</li>
<li>sub sub menu</li>
</ul>
</li>
</ul>
</li>
<li>
Menu4
</li>
<li>
Menu5
</li>
</ul>
</div>
</div>
ul, li {
margin:0; padding:0; list-style:none; text-decoration:none; color:#fff}
a { text-decoration:none;
color:#fff}
#nav ul {
width:100%;}
#nav ul li {
float:left; padding:0 15px; line-height:40px;}
body {
overflow: hidden;
}
#header {
background: none repeat scroll 0 0 #808080;
box-shadow: 1px 2px 3px #000;
float: left;
height: 50px;
width: 87%;
}
#nav ul li {
float: left;
line-height: 51px;
padding: 0 15px;
}
#nav ul > li:hover {
background-color: #000;
}
#nav ul li > ul {
background-color: #000;
display: none;
position: absolute;
top: 59px;
width: 150px;
}
#nav ul li:hover > ul {
display:block}
#nav ul li > ul > li {
background: none repeat scroll 0 0 #999;
border-bottom: 1px solid;
margin: 0;
padding: 0;
position: relative;
text-align: center;
text-transform: capitalize;
width: 100%;
}
#nav ul li > ul > li > ul {
background: none repeat scroll 0 0 pink;
display: none;
left: 150px;
position: absolute;
text-align: center;
top: 0;
}
#nav ul li > ul > li:hover ul {
display:block}
#nav ul li > ul > li > ul > li {
background: none repeat scroll 0 0 pink;
color: #000;
margin: 0;
padding: 0;
position: relative;
width: 100%;
}

css navigation bar problems with the submenus

I am hoping that someone could help me out with a css problem that has been driving me crazy all day. I know I'm missing something obvious here, I just don't see it. If you can help that would be greatly appreciated.
Here is the fiddle http://jsfiddle.net/taglegacy/HK7Hy/
And here is the css:
body
{
margin: 20;
padding: 20;
text-align: center;
font: 85% arial, helvetica, sans-serif;
background: #f1f1f1;
color: #444;
}
#container
{
text-align: left;
margin: 0 auto;
width: 700px;
height: 400px;
background: #FFF;
}
/*---NavigationBar---*/
ul
{
font-family: Arial, Verdana;
font-size: 14px;
width: 100%;
margin: 0;
padding: 0;
list-style: none;
float: left;
background: #9b1b19;
}
ul li
{
display: block;
position: relative;
float: left;
border-right: 1px solid #fff;
}
li ul
{
display: none;
position:absolute;
left:0;
}
ul li a
{
display: block;
text-decoration: none;
color: #fff;
padding: 5px 15px 5px 15px;
background: #9b1b19;
margin-left: 1px;
white-space: nowrap;
}
ul li a:hover
{
background: #af1f1c;
}
li:hover ul
{
display: block;
position: absolute;
background: #af1f1c;
}
li:hover li
{
float: none;
font-size: 11px;
background: #af1f1c;
border-top: 1px solid #fff;
}
li:hover a
{
background: #af1f1c;
}
li:hover li a:hover
{
background: #af1f1c;
}
Here is the HTML:
<body>
<div id="container">
<ul>
<li>Menu 1</li>
<li>Menu 2
<ul>
<li>Submenu 1</li>
<li>Submenu 2</li>
<li>Submenu 3</li>
</ul>
</li>
<li>Menu 3
<ul>
<li>Submenu 1</li>
<li>Submenu 2</li>
<li>Submenu 3</li>
<li>Submenu 4</li>
<li>Submenu 6</li>
</ul>
</li>
<li>Menu 4
<ul>
<li>Submenu 1</li>
<li>Submenu 2</li>
<li>Really Long Submenu 3 Really Long</li>
</ul>
</li>
</ul>
</div>
</body>
The "really long" list item is being cut off because your submenu ul is set to the width of it's parent li. Take out the width: 100% and it'll show the enter text.
Move it so that it only applies to the parent ul to retain the navbar width:
#topnav { width: 100% }
Fiddle
I think, a position:absolute is needed for the 2nd ul. Play around a bit with padding-top and/or top. In the example the padding-top is equal to height of main menu items.
ul#topnav > li > ul {position: absolute; top:0; left:0; padding-top:36px;}
should work, good luck!

Suckerfish drop-down submenu not aligned with main menu

I'm quite new with CSS so any help greatly appreciated. I'm currently using the Suckerfish script for my CSS menu, only because IE still exists. However, I can't get the second level menu to align directly under the first level -- not just IE, but Chrome and Safari as well.
I looked up solutions on this website, but I can't get them to work for my code...
Here's my CSS code (I'm sorry if it's messy):
#navbar {
width: 900px;
color: #a26868;
font-size: 10px;
padding: 10px 10px 10px 10px;
float: left;
background: #fff ;
}
#nav, #nav ul {
padding: 0px 15px 0px 15px;
margin: 0;
list-style: none;
line-height: 18px;
}
#nav a {
display: block;
width: 140px;
}
#navbar li {
list-style: none;
float: left;
padding: 0px 15px 0px 15px;
display: block;
width: 140px;
text-align: center;
height: 18px;
background-image: url(line-nav.gif);
background-repeat: no-repeat;
background-position: center;
text-decoration: none;
}
#navbar li a {
text-decoration: none;
color: #a26868;
}
#navbar li ul {
list-style: none;
color: #5e0505;
background-image: url(line-nav.gif);
background-repeat: no-repeat;
background-position: center;
background: rgba(255,255,255,0.8);
border-bottom: solid 1px #88c657;
width: 140px;
display: block;
position: relative;
left:-999em;
}
#navbar li:hover ul, #navbar li.sfhover ul {
left: 0;
}
And this is the HTML code:
<ul id="navbar">
<li>ABOUT<ul>
<li>SUBITEM ONE</li>
<li>SUBITEM TWO</li>
<li>SUBITEM THREE</li></ul>
</li>
<li>SHOWCASE<ul>
<li>SUBITEM ONE</li>
<li>SUBITEM TWO</li>
<li>SUBITEM THREE</li></ul>
</li>
<li>PORTFOLIO<ul>
<li>SUBITEM ONE</li>
<li>SUBITEM TWO</li>
<li>SUBITEM THREE</li></ul>
</li>
<li>MEDIA<ul>
<li>SUBITEM ONE</li>
<li>SUBITEM TWO</li>
<li>SUBITEM THREE</li></ul>
</li>
<li>CONTACT<ul>
<li>SUBITEM ONE</li>
<li>SUBITEM TWO</li>
<li>SUBITEM THREE</li></ul>
</li>
</ul>
Please, any help greatly appreciated. Thank you so much!
try this one,
#navbar li:hover ul, #navbar li.sfhover ul {
left:-50px;
}
http://jsfiddle.net/Yt66E/
your sub menu ul has padding and li too so you need to remove these paddings like this:
edit this CSS:
#navbar li:hover ul, #navbar li.sfhover ul {
left: 0;
padding:0; /* added */
}
and add this CSS:
#navbar li li{
padding:0;
}
jsFiddle is here

dropdown under a nav button css/html

I have a navcontainer with buttons in the container. I need to make a dropdown list for only one of the buttons. How would this be accomplished with CSS/HTML. Here is my code:
HTML:
<div id="navcontainer">
About Us
Request a Quote
Affiliates
Pricing & Plans
Additional Services
Service Details
Watering
</div>
CSS:
#navcontainer {
float: right;
width: 1040px;
height: 45px;
text-align: center;
line-height: 45px;
color: #fff;
margin-bottom: 6px;
}
.button {
text-align: center;
background: #226426;
color: #fff;
width: 100px;
height: 45px;
float: left;
text-decoration: none;
font-family: Arial, sans-serif;
font-size: 15px;
font-weight: bold;
border-right: solid 1px #91b293;
border-top: solid 1px #91b293;
border-bottom: solid 1px #91b293;
}
Do I need to make this into a ul or can I keep it as is, and just add a dropdown to the Services button? Thanks for your help.
As a general rule, it's always a good idea to have your navigation in a list, it helps keep your options open to a multidimensional menu system at any point. Here is what I would do:
HTML
<ul id="nav">
<li>link 1</li>
<li>link 2
<ul>
<li>sublink 1</li>
<li>sublink 2</li>
</ul>
</li>
<li>link 3</li>
</ul>
CSS
#nav, #nav ul {list-style: none; margin: 0; padding: 0;}
#nav li {position: relative;}
#nav li ul {position: absolute; top: 100%; left: 0; display: none;}
#nav li:hover ul {display: block;}
jQuery - optional
This is if you wanted some sort of effect on the
function mainmenu(){
$(" #nav ul ").css({display: "none"}); // Opera Fix
$(" #nav li").hover(function(){
$(this).find('ul:first').css({visibility: "visible",display: none"}).show(800);
},function(){
$(this).find('ul:first').css({visibility: "hidden"});
});
}
Hope this helps.

Resources