Auto width for submenu - html

I can't get this to work, but in my dropdown menu I just simply can't find a way to make the dropdown menu (for example on account) have it scale with the text.
I tried many things, but only so far a static width is working but that is not what I want
<div class="menu-wrap">
<div class="menu">
<ul class="menu-inner">
<li class="home">Home</li>
<li class="account">Mijn Account
<ul>
<li>Mijn website</li>
<li>Profiel</li>
<li>Persoonlijke gegevens</li>
<li>Voorkeuren</li>
<li>Email instellingen</li>
<li>Log uit</li>
</ul>
</li>
<li class="pages">Mijn pagina's
<ul>
<li>Mijn pagina's</li>
<li>Maak een nieuwe pagina</li>
<li>Verander pagina volgorde</li>
</ul>
</li>
<li class="messages">Mijn berichten
<ul>
<li>Alle privè berichten</li>
<li>Verzonden berichten</li>
<li>Verwijderde berichten</li>
<li>Ongelezen berichten</li>
</ul>
</li>
<li class="forum">Forum
<ul>
<li>Nieuwste berichten</li>
<li>Overzicht</li>
<li>Mijn berichten</li>
<li>Top posters</li>
<li>Zoek topic</li>
</ul>
</li>
<li class="search">Zoeken
<ul>
<li>Zoeken</li>
<li>Vandaag jarig</li>
<li>Online leden</li>
<li>Alle leden</li>
<li>Zoek topic</li>
</ul>
</li>
<li class="online">Online (x)
</ul>
</div>
</div>
and the css code:
.menu-wrap{
position: relative;
background-color: rgba(0,0,0,0.8);
height: 30px;
width: 100%;
text-align: center;
}
.menu {
position: relative;
width: 860px;
margin: 0px auto;
height: 30px;
line-height: 30px;
}
.menu ul {
text-align: left;
display: inline;
margin: 0;
padding: 0;
list-style: none;
}
.menu ul li {
font: bold 12px/18px sans-serif;
display: inline-block;
margin-right: -4px;
position: relative;
padding: 5px 22px;
cursor: pointer;
-webkit-transition: all 0.2s;
-moz-transition: all 0.2s;
-ms-transition: all 0.2s;
-o-transition: all 0.2s;
transition: all 0.2s;
}
.menu ul li:hover {
background-color: rgba(0,0,0,0.4);
}
.menu ul li a {
color: #fff;
text-decoration: none;
font-size: 14px;
}
.menu ul li ul {
padding: 0;
position: absolute;
top: 28px;
left: 0;
width: auto;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
display: none;
opacity: 0;
visibility: hidden;
-webkit-transiton: opacity 0.2s;
-moz-transition: opacity 0.2s;
-ms-transition: opacity 0.2s;
-o-transition: opacity 0.2s;
-transition: opacity 0.2s;
background-color: rgba(0,0,0,0.4)
}
.menu ul li ul li {
color: #fff;
}
.menu ul li ul li:hover { background-color: rgba(0,0,0,0.4);}
.menu ul li:hover ul {
display:inline-block;
opacity: 1;
visibility: visible;
}
All I want is have the sub menus auto scale in width with the text!

You are going to have to add a white-space property to the .menu ul li ul li rule like so:
.menu ul li ul li {
white-space: nowrap;
}

Related

Nested Menu CSS Hover Fade

I modified this menu and added css opacity hover transition.
It only works on the first ul, but the nested sub ul's will not show.
https://jsfiddle.net/sh73vvgf/
Replacing the fade effect with display: none; will show the sub menus.
https://jsfiddle.net/v8op2tqv/
How can I get fade to work on the sub menus? I need it to be pure html/css.
HTML
This nested menu shows a list of Planets and their Moons.
<div class="nav-main">
<ul>
<li>
Planets
<ul>
<li>
Jupiter
<!-- Moons -->
<ul>
<li>
Europa
</li>
<li>
Ganymede
</li>
<li>
Callisto
</li>
</ul>
</li>
<li>
Saturn
<!-- Moons -->
<ul>
<li>
Mimas
</li>
<li>
Dione
</li>
<li>
Titan
</li>
</ul>
</li>
<li>
Uranus
<!-- Moons -->
<ul>
<li>
Umbriel
</li>
<li>
Ariel
</li>
<li>
Oberon
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
CSS
.nav-main ul {
cursor: default;
font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
position: relative;
width: 300px;
padding: 0;
margin: 0;
background: #000;
font-size: 1em;
color: #fff;
list-style: none;
}
.nav-main ul li {
display: block;
position: relative;
float: left;
min-width: 25%;
padding: 0.3em;
min-width: 100px;
}
.nav-main ul li a {
display: block;
padding: 1.2em;
text-decoration: none;
text-align: center;
white-space: nowrap;
color: #fff;
}
/* Hover Fade */
.nav-main li ul {
webkit-transition: opacity 0.3s ease-out, -webkit-transform 0.3s ease-out;
-moz-transition: opacity 0.3s ease-out, -moz-transform 0.3s ease-out;
transition: opacity 0.3s ease-out, transform 0.3s ease-out;
opacity: 0;
height: 0;
width: 0;
overflow: hidden;
}
.nav-main li:hover > ul {
display: block;
position: absolute;
opacity: 1;
height: auto;
width: auto;
}
.nav-main li:hover li {
float: none;
}
.nav-main ul ul ul {
left: 100%;
top: 0;
}
.nav-main ul:before,
.nav-main ul:after {
content: " "; /* 1 */
display: table; /* 2 */
}
.nav-main ul:after {
clear: both;
}
I changed some "overflow" style of your code.
.nav-main ul {
cursor: default;
font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
position: relative;
width: 300px;
padding: 0;
margin: 0;
background: #000;
font-size: 1em;
color: #fff;
list-style: none;
overflow:hidden;
}
.nav-main ul:hover {
overflow:visible;
}
.nav-main ul li {
display: block;
position: relative;
float: left;
min-width: 25%;
padding: 0.3em;
min-width: 100px;
}
.nav-main ul li a {
display: block;
padding: 1.2em;
text-decoration: none;
text-align: center;
white-space: nowrap;
color: #fff;
}
/* Hover Fade */
.nav-main li ul {
webkit-transition: opacity 0.3s ease-out, -webkit-transform 0.3s ease-out;
-moz-transition: opacity 0.3s ease-out, -moz-transform 0.3s ease-out;
transition: opacity 0.3s ease-out, transform 0.3s ease-out;
opacity: 0;
height: 0;
width: 0;
//overflow: hidden;
}
.nav-main li:hover > ul {
display: block;
position: absolute;
opacity: 1;
height: auto;
width: auto;
}
.nav-main li:hover li {
float: none;
}
.nav-main ul ul ul {
left: 100%;
top: 0;
}
.nav-main ul:before,
.nav-main ul:after {
content: " "; /* 1 */
display: table; /* 2 */
}
.nav-main ul:after {
clear: both;
}
<div class="nav-main">
<ul>
<li>
Planets
<ul>
<li>
Jupiter
<!-- Moons -->
<ul>
<li>
Europa
</li>
<li>
Ganymede
</li>
<li>
Callisto
</li>
</ul>
</li>
<li>
Saturn
<!-- Moons -->
<ul>
<li>
Mimas
</li>
<li>
Dione
</li>
<li>
Titan
</li>
</ul>
</li>
<li>
Uranus
<!-- Moons -->
<ul>
<li>
Umbriel
</li>
<li>
Ariel
</li>
<li>
Oberon
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>

How Do I give the active menu items a different color - HTML5 CSS

I am trying to add a different color to my active menu items.
I have tried a few different ways but, there must be something I'm missing.
Here is my code:
#menu ul {
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
user-select: none;
color: #3d4449;
font-family: "Roboto Slab", serif;
font-family: 400;
letter-spacing: 0.075em;
list-style: none;
margin-bottom: 0;
padding: 0;
text-transform: uppercase;
}
#menu ul a,
#menu ul span {
border-bottom: 0;
color: inherit;
cursor: pointer;
display: block;
font-size: 0.9em;
padding: 0.625em 0;
}
#menu ul a:hover,
#menu ul span:hover {
color: #efa341;
}
#menu ul a.opener,
#menu ul span.opener {
-moz-transition: color 0.2s ease-in-out;
-webkit-transition: color 0.2s ease-in-out;
-ms-transition: color 0.2s ease-in-out;
transition: color 0.2s ease-in-out;
text-decoration: none;
-webkit-tap-highlight-color: rgba(255, 255, 255, 0);
position: relative;
}
#menu ul a.opener:before,
#menu ul span.opener:before {
-moz-osx-font-smoothing: grayscale;
-webkit-font-smoothing: antialiased;
font-family: FontAwesome;
font-style: normal;
font-weight: normal;
text-transform: none !important;
}
#menu ul a.opener:before,
#menu ul span.opener:before {
-moz-transition: color 0.2s ease-in-out, -moz-transform 0.2s ease-in-out;
-webkit-transition: color 0.2s ease-in-out, -webkit-transform 0.2s ease-in-out;
-ms-transition: color 0.2s ease-in-out, -ms-transform 0.2s ease-in-out;
transition: color 0.2s ease-in-out, transform 0.2s ease-in-out;
color: #9fa3a6;
content: '\f078';
position: absolute;
right: 0;
}
#menu ul a.opener:hover:before,
#menu ul span.opener:hover:before {
color: #eda547;
}
#menu ul a.opener.active + ul,
#menu ul span.opener.active + ul {
display: block;
}
#menu ul a.opener.active:before,
#menu ul span.opener.active:before {
-moz-transform: rotate(-180deg);
-webkit-transform: rotate(-180deg);
-ms-transform: rotate(-180deg);
transform: rotate(-180deg);
}
#menu > ul > li {
border-top: solid 1px rgba(210, 215, 217, 0.75);
margin: 0.5em 0 0 0;
padding: 0.5em 0 0 0;
}
#menu > ul > li > ul {
color: #9fa3a6;
display: none;
margin: 0.5em 0 1.5em 0;
padding-left: 1em;
}
#menu > ul > li > ul a,
#menu > ul > li > ul span {
font-size: 0.8em;
}
#menu > ul > li > ul > li {
margin: 0.125em 0 0 0;
padding: 0.125em 0 0 0;
}
#menu > ul > li:first-child {
border-top: 0;
margin-top: 0;
padding-top: 0;
}
<nav id="menu">
<header class="major">
<h2>Menu</h2>
</header>
<ul>
<li>Home
</li>
<li>
<span class="opener">Services</span>
<ul>
<li>Web Development
</li>
<li>Customised Software Development
</li>
<li>E-commerce Solutions
</li>
<li>Software Maintenace
</li>
</ul>
</li>
<li>
<span class="opener">Products</span>
<ul>
<li>Practice Management Application
</li>
<li>Electronic Claims
</li>
<li>Electronic Invoicing
</li>
<li>Debt Recovery
</li>
<li>Automated account collection
</li>
<li>Learner Management System
</li>
</ul>
</li>
<li>Projects
</li>
<li>About Us
</li>
<li>Contact Us
</li>
</ul>
</nav>
you need to apply class like "active" to respective menu and apply css to it
like
#menu ul > li.active > a{
color: red;
}
You need to apply a class to the active menu item.
For example:
#menu ul > li.active > a{
color: red;
background:yellow;
}
Adding the css from above to your code gives you this result:
#menu ul {
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
user-select: none;
color: #3d4449;
font-family: "Roboto Slab", serif;
font-family: 400;
letter-spacing: 0.075em;
list-style: none;
margin-bottom: 0;
padding: 0;
text-transform: uppercase;
}
#menu ul a,
#menu ul span {
border-bottom: 0;
color: inherit;
cursor: pointer;
display: block;
font-size: 0.9em;
padding: 0.625em 0;
}
#menu ul a:hover,
#menu ul span:hover {
color: #efa341;
}
#menu ul a.opener,
#menu ul span.opener {
-moz-transition: color 0.2s ease-in-out;
-webkit-transition: color 0.2s ease-in-out;
-ms-transition: color 0.2s ease-in-out;
transition: color 0.2s ease-in-out;
text-decoration: none;
-webkit-tap-highlight-color: rgba(255, 255, 255, 0);
position: relative;
}
#menu ul > li.active > a{
color: red;
}
<nav id="menu">
<header class="major">
<h2>Menu</h2>
</header>
<ul>
<li class="active">Home
</li>
<li>
<span class="opener">Services</span>
<ul>
<li>Web Development
</li>
<li>Customised Software Development
</li>
<li>E-commerce Solutions
</li>
<li>Software Maintenace
</li>
</ul>
</li>
<li>
<span class="opener">Products</span>
<ul>
<li>Practice Management Application
</li>
<li>Electronic Claims
</li>
<li>Electronic Invoicing
</li>
<li>Debt Recovery
</li>
<li>Automated account collection
</li>
<li>Learner Management System
</li>
</ul>
</li>
<li>Projects
</li>
<li>About Us
</li>
<li>Contact Us
</li>
</ul>
</nav>
You can use link:active in CSS like this:
menu ul a:active,
menu ul span:active {
color: #ff0000;
}
It will allow you to adjust whatever you need when the link is clicked and active.
To sum it up:
You want to have active menu items to be styled differently
To achieve this without using JavaScript you have to add a class like "active" (as mentioned above) to your list item tag
You have to do that for each site with its active menu item
Also prefer to change style for list element (like Rahul's answer) rather than applying it to the ulclass like you did in your css.
#menu > li.active > a{ color: #f46e28; }
this will help you definitely.

parent item drop up with sub menu

hello is it possible that when I hover to the parent item the parent item will also slide up making the drop down menu with parent item above it? here is my code but I cant seem to make it work. here is a visual menu that i want http://imgur.com/om9mvdG (the second image)
.nav ul {
*zoom: 1;
list-style: none;
margin: 0;
padding: 0;
background: #333;
}
.nav ul:before,
.nav ul:after {
content: "";
display: table;
}
.nav ul:after {
clear: both;
}
.nav ul > li {
float: left;
position: relative;
}
.nav a {
display: block;
padding: 10px 20px;
line-height: 1.2em;
color: #fff;
border-left: 1px solid #595959;
}
.nav a:hover {
text-decoration: none;
background: #595959;
}
.nav li ul {
background: #273754;
position: absolute;
left: 0;
bottom: 36px;
z-index: 1;
}
.nav li ul li {
width: 100%;
overflow: hidden;
height: 0;
-webkit-transition: height 200ms ease-in;
-moz-transition: height 200ms ease-in;
-o-transition: height 200ms ease-in;
transition: height 200ms ease-in;
}
.nav li ul a {
border: none;
}
.nav li ul a:hover {
background: rgba(0, 0, 0, 0.2);
}
.nav ul > li:hover ul li {
height: 36px;
}
<ul>
<li>
Nav Item
<ul>
<li>Subnav
</li>
<li>Subnav
</li>
<li>Subnav
</li>
</ul>
</li>
<li>
Nav Item
<ul>
<li>Subnav
</li>
<li>Subnav
</li>
<li>Subnav
</li>
</ul>
</li>
</ul>
</nav>
Add this css to your already existing code. Is this what you wanted?
http://codepen.io/anon/pen/jbBgdg
li>ul {
display: none;
}
a:hover~ul {
display: block;
}

Third level drop down css wont show & content/links are out of order?

Some of the sub menu links of the third level are being shown in the second level while some of the second level content are not shown at all. On top of that, I don't know how to get the third level to appear at all. I'm sorry, I'm very new to this.
HTML:
<ul>
<li>Home</li>
<li>Bio</li>
<li>Portfolio
<ul>
<li>Design</li>
<ul>
<li>Illustartor</li>
<li>InDesign</li>
<li>Photoshop</li>
</ul>
<li>Media</li>
<ul>
<li>Photography</li>
<li>Video</li>
</ul>
<li>Traditional</li>
<ul>
<li>Paintings</li>
<li>Drawings</li>
</ul>
</ul>
</li>
<li>FAQ</li>
<li>Contact</li>
</ul>
CSS:
ul {
text-align: left;
display: inline;
margin: 0;
padding: 15px 4px 17px 0;
list-style: none;
-webkit-box-shadow: 0 0 5px rgba(0, 0, 0, 0.15);
-moz-box-shadow: 0 0 5px rgba(0, 0, 0, 0.15);
box-shadow: 0 0 5px rgba(0, 0, 0, 0.15);
top: 400px;
index-z: 3;
}
ul li {
font: bold 12px/18px sans-serif;
display: inline-block;
margin-right: -4px;
position: relative;
padding: 15px 20px;
background: #fff;
cursor: pointer;
-webkit-transition: all 0.2s;
-moz-transition: all 0.2s;
-ms-transition: all 0.2s;
-o-transition: all 0.2s;
transition: all 0.2s;
width: 141px;
}
ul li:hover {
background: #555;
color: #fff;
-webkit-transition: delay .5s ease-in-out;
-moz-transition: delay .5s ease-in-out;
-o-transition: delay .5s ease-in-out;
}
ul li ul {
padding: 0;
position: absolute;
top: 48px;
left: 0;
width: 150px;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
display: none;
opacity: 0;
visibility: hidden;
-webkit-transiton: opacity 0.2s;
-moz-transition: opacity 0.2s;
-ms-transition: opacity 0.2s;
-o-transition: opacity 0.2s;
-transition: opacity 0.2s;
}
ul li ul li {
background: #555;
display: block;
color: #fff;
text-shadow: 0 -1px 0 #000;
}
ul li ul li:hover { background: #666; }
ul li:hover ul {
display: block;
opacity: 1;
visibility: visible;
}
li ul li ul{ /* Third Level & beyond ***********/
display:none;
background:#55aa7f;
}
li ul li:hover ul{
display:block;
position:absolute;
left:100%;
border-left:solid 3px #fff;
top:0;
width:auto;
}
li ul li ul li{
display:block;
padding:3px 10px;
border-top:solid 3px #fff;
white-space:nowrap;
}
li ul li ul li:hover span{
color:#fff;
}
.levelThreeAlign{position:relative;}
You have closed each list item in the submenu before the ul for the sub-submenu.
html should look like this fiddle:
<ul>
<li>Home</li>
<li>Bio</li>
<li>Portfolio
<ul>
<li>Design
<ul>
<li>Illustartor</li>
<li>InDesign</li>
<li>Photoshop</li>
</ul>
</li>
<li>Media
<ul>
<li>Photography</li>
<li>Video</li>
</ul>
</li>
<li>Traditional
<ul>
<li>Paintings</li>
<li>Drawings</li>
</ul>
</li>
</ul>
</li>
<li>FAQ</li>
<li>Contact</li>
</ul>
I have changed some of the css in the fiddle as well utilizing direct descendent selectors. Inheritance is very important here. when you style ul li { that will cascade down to ul li ul li { as you are styling all li that are children of a ul. doesn't matter how many levels deep.

Navigation submenu switches to other submenu on hover

I have a navigation menu that I'm trying to get to work, but the submenus keep switching to another submenu whenever I hover over it. How can I get it so that the right menu stays up when I hover over it?
jsfiddle: http://jsfiddle.net/SHQwm/
.hoverBar {
position: relative;
border: 1px solid #d6d6d6;
background: #fff;
padding: 15px 20px;
height: 100px;
}
ul {
margin: 0;
padding: 0;
width: 1152px;
}
.mainmenu > li {
list-style: none;
float:left;
text-align: center;
}
ul.mainmenu > li a {
font-family: 'Open Sans', sans-serif;
padding: 0 10px;
font-size: 11px;
text-decoration: none;
text-transform: uppercase;
}
ul li ul {
opacity: 0;
transition: opacity .15s ease-in-out;
-moz-transition: opacity .15s ease-in-out;
-webkit-transition: opacity .15s ease-in-out;
-o-transition: opacity .15s ease-in-out;
list-style-type: none;
text-align: left;
float: left;
width: 100%;
position: absolute;
z-index: 60;
left: 0;
padding-top: 30px;
}
ul li:hover ul {
opacity: 1;
}
ul li ul li {
float: left;
text-align: left;
border-top: #4c4c4c 1px solid;
border-bottom: #303030 1px solid;
border-radius: 2px;
margin-bottom: 0;
padding: 10px 0;
white-space: nowrap;
width: auto;
}
ul li ul li:hover {
background-color: #008000;
}
.floatr {
position: absolute;
top: 10px;
z-index: 50;
width: 100px;
height: 30px;
background : #ebebeb;
opacity: 0.25;
-ms-transition: all .4s ease-in-out;
-webkit-transition: all .4s ease-in-out;
-moz-transition: all .4s ease-in-out;
border-top: solid 1px #00aced;
border-bottom: solid 1px #00aced;
}
.mainmenu > li:hover > a {
opacity: 1;
}
ul li ul li a {
display: block;
padding: 0px;
line-height: 14px;
font-size: 12px;
color: #000;
font-family: 'Open Sans', sans-serif;
text-transform: none !important;
text-align: left;
}
ul li:hover ul li {
display:block;
}
.mainmenu {
height: 100px;
}
#jobBank {
left: 450;
width: 210px;
}
And the HTML:
<nav class="head_nav">
<div class="hoverBar" >
<ul class="mainmenu">
<li class="active">About
<ul style="background-color: red;">
<li>Mission</li>
<li>Board Members</li>
<li>Staff</li>
<li>Members</li>
<li>Task Forces</li>
</ul>
</li>
<li>Events
<ul style="background-color: green;">
<li>Description</li>
<li>Registration with Outlook ICS</li>
<li>Online Payment</li>
<li>Email auto-reminders</li>
<li>Multiple registrants allowed</li>
</ul>
</li>
<li>Galleries
<ul style="background-color: blue;">
<li>EXAMPLE: Executive Board</li>
<li>EXAMPLE: Single Page or Blog Page</li>
<li>EXAMPLE: Photo Gallery</li>
</ul>
</li>
<li>Educational Resources</li>
<li>Economic Development
<ul style="background-color: yellow;">
<li>Major Corporations/Global Businesses</li>
<li>Maps</li>
<li>Available Properties</li>
<li>Communities Represented</li>
<li>Demographics</li>
<li>Workforce</li>
<li>Taxes</li>
<li>Transportation</li>
<li>Utilities</li>
<li>Incentives & Financing</li>
<li>Report and Publications</li>
</ul>
</li>
</li>
<li>Media Room
<ul>
<li class="first">Press Releases</li>
<li>Media Kit Information</li>
<li>Blog</li>
<li>Link to Logo & Standards</li>
<li>Link to Photo Gallery</li>
<li>Twitter, Facebook, LinkedIn, Flickr</li>
<li>Speakers Bureau List/info</li>
<li>Fact Sheet</li>
<li class="last">Media Relations Contact</li>
</ul>
</li>
<li>Job Bank
<ul id="jobBank">
<li class="first">Member Add/Edit/Delete</li>
<li class="last">Time Expire</li>
</ul>
</li>
</ul>
<div class="floatr"></div>
</div>
</nav>
Remove opacity: 0 from ul li ul. Replace it with display: none;. Remove opacity: 1 from ul li:hover ul. Replace it with display: block;. Currently, all of the subnavigations are there, you just can't see them. Setting them to display: none; by default will only display the correct one when the parent navigation element is hovered and will remove the issue you're having. http://jsfiddle.net/SHQwm/5/