For whatever reason, when I add a radio check into the css, it will appear in the menu but will not show any of the menu items. Any tips on getting it to toggle properly would be a huge help!
Here's the fiddle:
http://jsfiddle.net/casslt07/kjjvp1bx/
**HTML**
<div id="nav">
<nav id="nav" class="clearfix">
<!-- nav menu top level -->
<input type="checkbox" id="menu-toggle">
<label for="button" onclick></label>
<ul class="first-level">
<li>Home
<li><a>Posts</a>
<ul>
<li>Listings</li>
<li>Comics</li>
<li>Observations</li>
<li>Poems</li>
<li>Short Stories</li>
</ul>
</li>
<li>Photos
</li>
<li>Videos</li>
<li>About the Author</li>
</ul>
<?php get_search_form(); ?> </nav>
</div>
**CSS:**
/* Config */
body {font-family:Arial}
ul, li {list-style:none; margin:0; padding:0;}
#menu-toggle {
display:none;
}
#nav label {
display:none;
font-size:20px;
list-style:none;
}
/* Nav */
#nav {
background-color:#33447A;
height: inherit;
border-bottom: 3px solid #13EBC7;
position:relative;
display:block; width: 100%; overflow:visible;}
#nav a {
color:#fff; display:block; font-size: 11pt; padding:18px 20px; text-decoration:none; text-align: left;}
#nav ul li {position:relative;}
/* First-Level */
#nav li {transition:background-color .5s; float:left;}
#nav li:hover {background-color:#50AEED; -webkit-transition: margin-bottom .2s; /* Safari 3.1 to 6.0 */
transition: margin-bottom .2s;}
#nav > ul > li {display:block; float:left; }
/* Second-level */
#nav li ul {width: 100%;}
#nav > ul li:hover > ul {opacity:1; top:54px; visibility:visible; border-radius: 4px; z-index:3; }
#nav .first-level .second-level > li {float:left;}
#nav > ul ul {opacity:0; visibility:hidden; position:absolute; top:60px; transition:all .25s; width:1000px;}
#nav > ul ul li {background-color:#3498db; left:0;}
#nav > ul ul li a {padding:10px 20px}
/* Clearfix */
.clearfix:after {visibility: hidden; display: block; font-size: 0; content:" "; clear:both; height:0;}
.nav-search {
opacity: .25;
width:35%;
float: right;
display:inline;
position: relative;
background: #3498db;
background: url('http://1touchsigns.com/images/search.gif');
background-repeat: no-repeat;
-webkit-border-radius:10px;
-moz-border-radius:10px;
border-radius:10px;
border:none;
top:7px;
padding:6px;
outline:none;
transition: all .3s ease-in-out;
-moz-transition: all .3s ease-in-out;
-webkit-transition: all .3s ease-in-out;
}
.nav-search:focus {
background: white;
opacity: 1;
}
#responsive {
display: none;
}
#media only screen and (max-width: 480px) {
#menu-toggle {
display:block;
}
#nav label {display: block;height:50px;width:50px;line-height:50px;text-align:center;color:white;font-size:150%;background-color: #83CE69; cursor:pointer;}
#menu-toggle:checked + #nav {display: block;}
#nav label:active #nav {display: none;}
#nav {
display: block;
width: 100%;
height:auto;
float: right;
margin-right: 10px;
background-color: #232323;
border-bottom-width: 0px;
}
#nav ul {
display:none;
}
#nav ul:hover {
display:block;
}
#nav li {
width:100%;
}
#nav ul ul li {
width:100%;
color:white;
background-color:black;
display:block;
}
#nav ul ul li:hover {
display:block;
}
}
Add
#menu-toggle:checked + label + ul {
display: block;
}
http://jsfiddle.net/kjjvp1bx/3/
Or use jQuery, both works:
http://jsfiddle.net/kjjvp1bx/2/
Related
http://jsfiddle.net/aw4zgwso/
Here's what's happening at the moment and I can't seem to center the nav menu unless I add something like width:40% to .menu But that doesn't work well and will knock the text down on smaller resolution displays
.nav {
width:100%;
height:40px;
display:block;
background-color:#313131;
}
.nav_inner {
height:100%;
margin:0 auto;
position:relative;
}
.nav_menu {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
height: 40px;
line-height: 15px;
}
.nav_menu li {
float: left;
}
.nav_menu li a {
display: block;
color:#ffffff;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.nav_menu a:hover {
background-color: red;
color:white;
}
.clearfix:after {
display:block;
clear:both;
}
/*----- Menu Outline -----*/
.menu-wrap {
width:100%;
background:#3e3436;
}
.menu {
margin:0px auto;
}
.menu li {
margin:0px;
list-style:none;
}
.menu a {
color:#ffffff;
text-decoration:none;
}
.menu li:hover > a, .menu .current-item > a {
text-decoration:none;
color:#ffffff;
}
.menu .arrow {
font-size:12px;
line-height:0%;
color:#00AAFF;
padding-left: 5px;
}
/*----- Top Level -----*/
.menu > ul > li {
float:left;
display:inline-block;
position:relative;
font-size:16px;
color: #ffffff;
}
.menu > ul > li > a {
padding:9px 40px;
display:inline-block;
}
.menu > ul > li:hover > a, .menu > ul > .current-item > a {
background:#191919;
}
/*----- Bottom Level -----*/
.menu li:hover .sub-menu {
z-index:1;
opacity:1;
}
.sub-menu {
width:160%;
padding:5px 0px;
position:absolute;
top:95%;
left:0px;
z-index:-1;
opacity:0;
transition:opacity linear 0.15s;
background:#313131;
}
.sub-menu li {
display:block;
font-size:16px;
}
.sub-menu li a {
padding:10px 30px;
display:block;
}
.sub-menu li a:hover, .sub-menu .current-item a {
background:#191919;
}
<div class="nav">
<div class="nav_inner">
<nav class="hide-mobile menu">
<ul class="clearfix">
<li>Home</li>
<li>About us<span class="arrow">▼</span>
<ul class="sub-menu">
<li>Our Values</li>
<li>Technology Partners</li>
</ul>
</li>
<li>IT Solutions<span class="arrow">▼</span>
<ul class="sub-menu">
<li>Audio Visual</li>
<li><a href="backup-replication-business-continuity.html">Backup, Replication and
<li>Visitor & Entry Management</li>
</ul>
</li>
<li>Contact Us</li>
</ul>
</nav>
</div>
</div>
You can simply use text-align:center and make li inline-block like this :
.menu>ul {
text-align: center;
margin: 0;
padding: 0;
}
.menu>ul>li {
display: inline-block;
position: relative;
font-size: 16px;
color: #ffffff;
}
here is the full code
.nav {
width: 100%;
height: 40px;
display: block;
background-color: #313131;
}
.nav_inner {
height: 100%;
margin: 0 auto;
position: relative;
}
.nav_menu {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
height: 40px;
line-height: 15px;
}
.nav_menu li {
float: left;
}
.nav_menu li a {
display: block;
color: #ffffff;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.nav_menu a:hover {
background-color: red;
color: white;
}
.clearfix:after {
display: block;
clear: both;
}
/*----- Menu Outline -----*/
.menu-wrap {
width: 100%;
background: #3e3436;
}
.menu {
margin: 0px auto;
}
.menu li {
margin: 0px;
list-style: none;
}
.menu a {
color: #ffffff;
text-decoration: none;
}
.menu li:hover>a,
.menu .current-item>a {
text-decoration: none;
color: #ffffff;
}
.menu .arrow {
font-size: 12px;
line-height: 0%;
color: #00AAFF;
padding-left: 5px;
}
/*----- Top Level -----*/
.menu>ul {
text-align: center;
margin: 0;
padding: 0;
}
.menu>ul>li {
display: inline-block;
position: relative;
font-size: 16px;
color: #ffffff;
}
.menu>ul>li>a {
padding: 9px 40px;
display: inline-block;
}
.menu>ul>li:hover>a,
.menu>ul>.current-item>a {
background: #191919;
}
/*----- Bottom Level -----*/
.menu li:hover .sub-menu {
z-index: 1;
opacity: 1;
}
.sub-menu {
width: 160%;
padding: 5px 0px;
position: absolute;
top: 95%;
left: 0px;
z-index: -1;
opacity: 0;
transition: opacity linear 0.15s;
background: #313131;
}
.sub-menu li {
display: block;
font-size: 16px;
}
.sub-menu li a {
padding: 10px 30px;
display: block;
}
.sub-menu li a:hover,
.sub-menu .current-item a {
background: #191919;
}
<div class="nav">
<div class="nav_inner">
<nav class="hide-mobile menu">
<ul class="clearfix">
<li>Home</li>
<li>About us<span class="arrow">▼</span>
<ul class="sub-menu">
<li>Our Values</li>
<li>Technology Partners</li>
</ul>
</li>
<li>IT Solutions<span class="arrow">▼</span>
<ul class="sub-menu">
<li>Audio Visual</li>
<li><a href="backup-replication-business-continuity.html">Backup, Replication and
<li>Visitor & Entry Management</li>
</ul>
</li>
<li>Contact Us</li>
</ul>
</nav>
</div>
</div>
try this :
ul {
text-align: center;
}
.menu > ul > li {
float: none;
}
Set text-align: center; for parent(.menu) and display: inline-block; for children(.clearfix).
.menu {
text-align: center;
}
.clearfix {
display: inline-block;
padding:0;
}
.menu li {
bottom: 12px;
//more code...
}
.nav { width:100%; height:40px; display:block; background-color:#313131;}
.nav_inner {height:100%; margin:0 auto; position:relative;}
.nav_menu {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
height: 40px;
line-height: 15px;
}
.nav_menu li {
float: left;
}
.nav_menu li a {
display: block;
color:#ffffff;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.nav_menu a:hover {
background-color: red;
color:white;
}
.clearfix:after {
display:block;
clear:both;
}
/*----- Menu Outline -----*/
.menu-wrap {
width:100%;
background:#3e3436;
}
.menu {
text-align: center;
}
.clearfix {
display: inline-block;
padding:0;
}
.menu li {
bottom: 12px;
list-style:none;
}
.menu a {
color:#ffffff;
text-decoration:none;
}
.menu li:hover > a, .menu .current-item > a {
text-decoration:none;
color:#ffffff;
}
.menu .arrow {
font-size:12px;
line-height:0%;
color:#00AAFF;
padding-left: 5px;
}
/*----- Top Level -----*/
.menu > ul > li {
float:left;
display:inline-block;
position:relative;
font-size:16px;
color: #ffffff;
}
.menu > ul > li > a {
padding:9px 40px;
display:inline-block;
}
.menu > ul > li:hover > a, .menu > ul > .current-item > a {
background:#191919;
}
/*----- Bottom Level -----*/
.menu li:hover .sub-menu {
z-index:1;
opacity:1;
}
.sub-menu {
width:160%;
padding:5px 0px;
position:absolute;
top:95%;
left:0px;
z-index:-1;
opacity:0;
transition:opacity linear 0.15s;
background:#313131;
}
.sub-menu li {
display:block;
font-size:16px;
}
.sub-menu li a {
padding:10px 30px;
display:block;
}
.sub-menu li a:hover, .sub-menu .current-item a {
background:#191919;
}
<div class="nav">
<div class="nav_inner">
<nav class="hide-mobile menu">
<ul class="clearfix">
<li>Home</li>
<li>About us<span class="arrow">▼</span>
<ul class="sub-menu">
<li>Our Values</li>
<li>Technology Partners</li>
</ul>
</li>
<li>IT Solutions<span class="arrow">▼</span>
<ul class="sub-menu">
<li>Audio Visual</li>
<li><a href="backup-replication-business-continuity.html">Backup, Replication and
<li>Visitor & Entry Management</li>
</ul>
</li>
<li>Contact Us</li>
</ul>
</nav>
</div>
</div>
To center the menu you just need to add this CSS to your menu. I'm diffinatly sure it's helpful for you.
.menu ul {
margin: 0 auto;
display: table;
}
.nav {
width:100%;
height:40px;
display:block;
background-color:#313131;
}
.nav_inner {
height:100%;
margin:0 auto;
position:relative;
}
.nav_menu {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
height: 40px;
line-height: 15px;
}
.nav_menu li {
float: left;
}
.nav_menu li a {
display: block;
color:#ffffff;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.nav_menu a:hover {
background-color: red;
color:white;
}
.clearfix:after {
display:block;
clear:both;
}
/*----- Menu Outline -----*/
.menu-wrap {
width:100%;
background:#3e3436;
}
.menu {
margin:0px auto;
}
.menu li {
margin:0px;
list-style:none;
}
.menu a {
color:#ffffff;
text-decoration:none;
}
.menu li:hover > a, .menu .current-item > a {
text-decoration:none;
color:#ffffff;
}
.menu .arrow {
font-size:12px;
line-height:0%;
color:#00AAFF;
padding-left: 5px;
}
/*----- Top Level -----*/
.menu > ul > li {
float:left;
display:inline-block;
position:relative;
font-size:16px;
color: #ffffff;
}
.menu > ul > li > a {
padding:9px 40px;
display:inline-block;
}
.menu > ul > li:hover > a, .menu > ul > .current-item > a {
background:#191919;
}
/*----- Bottom Level -----*/
.menu li:hover .sub-menu {
z-index:1;
opacity:1;
}
.sub-menu {
width:160%;
padding:5px 0px;
position:absolute;
top:95%;
left:0px;
z-index:-1;
opacity:0;
transition:opacity linear 0.15s;
background:#313131;
}
.sub-menu li {
display:block;
font-size:16px;
}
.sub-menu li a {
padding:10px 30px;
display:block;
}
.sub-menu li a:hover, .sub-menu .current-item a {
background:#191919;
}
<div class="nav">
<div class="nav_inner">
<nav class="hide-mobile menu">
<ul class="clearfix">
<li>Home</li>
<li>About us<span class="arrow">▼</span>
<ul class="sub-menu">
<li>Our Values</li>
<li>Technology Partners</li>
</ul>
</li>
<li>IT Solutions<span class="arrow">▼</span>
<ul class="sub-menu">
<li>Audio Visual</li>
<li><a href="backup-replication-business-continuity.html">Backup, Replication and
<li>Visitor & Entry Management</li>
</ul>
</li>
<li>Contact Us</li>
</ul>
</nav>
</div>
</div>
/HTML/
<div class="nav">
<div class="nav_inner">
<nav class="hide-mobile menu">
<ul class="navs">
<li>Home</li>
<li>About us<span class="arrow">▼</span>
<ul class="sub-menu">
<li>Our Values</li>
<li>Technology Partners</li>
</ul>
</li>
<li>IT Solutions<span class="arrow">▼</span>
<ul class="sub-menu">
<li>Audio Visual</li>
<li><a href="backup-replication-business-continuity.html">Backup, Replication and
<li>Visitor & Entry Management</li>
</ul>
</li>
<li>Contact Us</li>
</ul>
</nav>
</div>
</div>
.nav { width:100%;display:block; text-align:center;background-color:#313131;}
.nav_inner {height:100%; margin:0 auto; position:relative;text-align:center}
.nav_menu {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
line-height: 15px;
}
.nav_menu li {
display:inline-block;
}
.nav_menu li a {
display: block;
color:#ffffff;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.nav_menu a:hover {
background-color: red;
color:white;
}
.clearfix:after {
display:block;
clear:both;
}
/*----- Menu Outline -----*/
.menu-wrap {
width:100%;
background:#3e3436;
}
.menu {
margin:0px auto;
}
.menu li {
margin:0px;
list-style:none;
}
.menu a {
color:#ffffff;
text-decoration:none;
}
.menu li:hover > a, .menu .current-item > a {
text-decoration:none;
color:#ffffff;
}
.menu .arrow {
font-size:12px;
line-height:0%;
color:#00AAFF;
padding-left: 5px;
}
.navs {
float: left;
width: 100%;
}
/*----- Top Level -----*/
.menu > ul > li {
display:inline-block;
position:relative;
font-size:16px;
color: #ffffff;
}
.menu > ul > li > a {
padding:9px 40px;
display:inline-block;
}
.menu > ul > li:hover > a, .menu > ul > .current-item > a {
background:#191919;
}
/*----- Bottom Level -----*/
.menu li:hover .sub-menu {
z-index:1;
opacity:1;
}
.sub-menu {
width:160%;
padding:5px 0px;
position:absolute;
top:95%;
left:0px;
z-index:-1;
opacity:0;
transition:opacity linear 0.15s;
background:#313131;
}
.sub-menu li {
display:block;
font-size:16px;
}
.sub-menu li a {
padding:10px 30px;
display:block;
}
.sub-menu li a:hover, .sub-menu .current-item a {
background:#191919;
}
Using text-align: center to horizontally center nested elements
If you declare text-align: center on the containing parent element (.menu > ul), remove any arbitrary margin or padding that may offset horizontal alignment, and remove the float rule declared on the list items (li) - you should achieve the intended result.
Note: for horizontal alignment, using text-align: center to work as expected, a few requirements should be met:
The containing parent element must be a block element (e.g:
display: block)
The nested elements you need centered should be inline-block
elements (e.g: display: inline-block)
No float rules should be declared on the nested elements you are
intending to horizontally align, float rules will negate any effort
to align elements in this way
.nav {
width:100%;
height:40px;
display:block;
background-color:#313131;
}
.nav_inner {
height:100%;
margin:0 auto;
position:relative;
}
.nav_menu {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
height: 40px;
line-height: 15px;
}
/* Additional */
.menu > ul {
margin: auto;
padding: 0px; /* remove arbitrary padding */
text-align: center;
}
/* end Additional */
.nav_menu li {
float: left;
}
.nav_menu li a {
display: block;
color:#ffffff;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.nav_menu a:hover {
background-color: red;
color:white;
}
.clearfix:after {
display:block;
clear:both;
}
/*----- Menu Outline -----*/
.menu-wrap {
width:100%;
background:#3e3436;
}
.menu {
margin:0px auto;
}
.menu li {
margin:0px;
list-style:none;
}
.menu a {
color:#ffffff;
text-decoration:none;
}
.menu li:hover > a, .menu .current-item > a {
text-decoration:none;
color:#ffffff;
}
.menu .arrow {
font-size:12px;
line-height:0%;
color:#00AAFF;
padding-left: 5px;
}
/*----- Top Level -----*/
.menu > ul > li {
float:none; /* remove float */
display:inline-block;
position:relative;
font-size:16px;
color: #ffffff;
}
.menu > ul > li > a {
padding:9px 40px;
display:inline-block;
}
.menu > ul > li:hover > a, .menu > ul > .current-item > a {
background:#191919;
}
/*----- Bottom Level -----*/
.menu li:hover .sub-menu {
z-index:1;
opacity:1;
}
.sub-menu {
width:160%;
padding:5px 0px;
position:absolute;
top:95%;
left:0px;
z-index:-1;
opacity:0;
transition:opacity linear 0.15s;
background:#313131;
}
.sub-menu li {
display:block;
font-size:16px;
text-align: left; /* retain left text-alignment on submenu list items */
}
.sub-menu li a {
padding:10px 30px;
display:block;
}
.sub-menu li a:hover, .sub-menu .current-item a {
background:#191919;
}
<div class="nav">
<div class="nav_inner">
<nav class="hide-mobile menu">
<ul class="clearfix">
<li>Home</li>
<li>About us<span class="arrow">▼</span>
<ul class="sub-menu">
<li>Our Values</li>
<li>Technology Partners</li>
</ul>
</li>
<li>IT Solutions<span class="arrow">▼</span>
<ul class="sub-menu">
<li>Audio Visual</li>
<li><a href="backup-replication-business-continuity.html">Backup, Replication and
<li>Visitor & Entry Management</li>
</ul>
</li>
<li>Contact Us</li>
</ul>
</nav>
</div>
</div>
Or... you could Just use Flex...
Using flex-box to horizontally center nested elements
By declaring display: flex on a parent element and justify-content: center you will be able to horizontally center elements. flex-box is actually great for list items specifically since it usually required specific nested children, e.g: ordered (ol) or unordered (ul) lists only accept li elements as directly nested children for valid markup, and flex-box typically has a parent-to-direct-child "dependency" (so in other words, flex-box rules work great for directly nested children, but may adversely affect other elements nested deeper in/down the DOM tree in ways you are either not anticipating or do not desire).
/* Additional */
.menu > ul {
display: flex;
padding: 0px;
margin: auto;
justify-content: center;
}
See collapsed Code Snippet below demonstrating flex-box solution
.nav {
width:100%;
height:40px;
display:block;
background-color:#313131;
}
.nav_inner {
height:100%;
margin:0 auto;
position:relative;
}
.nav_menu {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
height: 40px;
line-height: 15px;
}
/* Additional */
.menu > ul {
display: flex;
padding: 0px;
margin: auto;
justify-content: center;
}
/* end Additional */
.nav_menu li {
float: left;
}
.nav_menu li a {
display: block;
color:#ffffff;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.nav_menu a:hover {
background-color: red;
color:white;
}
.clearfix:after {
display:block;
clear:both;
}
/*----- Menu Outline -----*/
.menu-wrap {
width:100%;
background:#3e3436;
}
.menu {
margin:0px auto;
}
.menu li {
margin:0px;
list-style:none;
}
.menu a {
color:#ffffff;
text-decoration:none;
}
.menu li:hover > a, .menu .current-item > a {
text-decoration:none;
color:#ffffff;
}
.menu .arrow {
font-size:12px;
line-height:0%;
color:#00AAFF;
padding-left: 5px;
}
/*----- Top Level -----*/
.menu > ul > li {
float:left;
display:inline-block;
position:relative;
font-size:16px;
color: #ffffff;
}
.menu > ul > li > a {
padding:9px 40px;
display:inline-block;
}
.menu > ul > li:hover > a, .menu > ul > .current-item > a {
background:#191919;
}
/*----- Bottom Level -----*/
.menu li:hover .sub-menu {
z-index:1;
opacity:1;
}
.sub-menu {
width:160%;
padding:5px 0px;
position:absolute;
top:95%;
left:0px;
z-index:-1;
opacity:0;
transition:opacity linear 0.15s;
background:#313131;
}
.sub-menu li {
display:block;
font-size:16px;
text-align: left; /* retain left text-alignment on submenu list items */
}
.sub-menu li a {
padding:10px 30px;
display:block;
}
.sub-menu li a:hover, .sub-menu .current-item a {
background:#191919;
}
<div class="nav">
<div class="nav_inner">
<nav class="hide-mobile menu">
<ul class="clearfix">
<li>Home</li>
<li>About us<span class="arrow">▼</span>
<ul class="sub-menu">
<li>Our Values</li>
<li>Technology Partners</li>
</ul>
</li>
<li>IT Solutions<span class="arrow">▼</span>
<ul class="sub-menu">
<li>Audio Visual</li>
<li><a href="backup-replication-business-continuity.html">Backup, Replication and
<li>Visitor & Entry Management</li>
</ul>
</li>
<li>Contact Us</li>
</ul>
</nav>
</div>
</div>
Heads up! flex-box has poor or limited support for legacy browsers, so if this is going to be a concern for you, it's probably better not to use it in production.
IE <= 9 - Not Supported
IE 10,11 - Partial Support
See more: https://caniuse.com/#feat=flexbox
I'm concluding a design and I'm facing an issue which I'm not familiar with. I'm trying to make a menu expand from hidden to visible over 2 seconds on hover using a transition: height CSS element.
The issue is that the ul is obeying the transition and appearing visible within 2s, however the lis are completely ignoring the transition effect and instantly expanding on hover.
CSS syntax below:
#main_navbar_container{
margin-bottom:0;
background:white;
}
.navbar-collapse {
text-align:center;
}
#menu_container{
width:80%;
float:right;
display:block;
}
#primary_menu{
display:block;
float:left;
width:100%;
}
#primary_menu ul{
list-style: none;
margin: 0;
padding-left: 0;
}
#primary_menu a,
#primary_menu a:visited,
#primary_menu a:link{
color:#ea474b;
font-weight: 600;
display: block;
text-decoration: none;
padding: 15px 20px;
margin:auto;
}
#primary_menu a:hover{
color:#F9690E;
}
#primary_menu li{
float:left;
position:relative;
margin:0
}
#primary_menu ul ul {
box-shadow: 0 3px 3px rgba(0, 0, 0, 0.2);
border-radius: 4px;
border: 1px solid #dadada;
background: #fff;
color: #8c9398;
float: right;
position: absolute;
top: 3.5em;
right: -999em;
z-index: 99999;
text-align: center
}
#primary_menu ul li:hover > ul {
right: 50%;
margin-right: -100%;
width: 200px;
}
.sub-menu li{
margin:0 15px !important;
}
#primary_menu ul li ul a{
color:#ea474b;
}
#primary_menu ul li ul:hover a{
color:#ea474b;
}
#primary_menu ul li ul li:hover a{
color:#F9690E;
}
#media (max-width: 1200px){
#main_navbar_container .container, #menu_container { width: 100%;}
#menu_container .navbar-collapse { padding: 0;}
#primary_menu{
width:100%;
margin:0;
}
#primary_menu li{
width:100%;
margin:5px 0 0 0;
}
#primary_menu ul li ul {
border-radius: 0 !important;
border-color: transparent !important;
display:hidden;
height:100px;
-webkit-transition: height 2s; /* Safari */
transition: height 2s;
}
#primary_menu ul li:hover{
background:none;
}
#primary_menu ul li:hover a{
font-color:black;
/*\color:rgb(207,0,15);*/
}
#primary_menu ul li:hover ul{
position:initial;
display:block;
background-color:rgb(238,238,238);
width:100%;
padding:0;
margin:0;
height:400px;
}
#primary_menu ul li:hover li:first-of-type{
border-top:1px solid rgb(238,238,238);
}
#primary_menu ul li:hover li:last-of-type{
border-bottom:1px solid rgb(238,238,238);
}
#primary_menu ul li:hover a:link,
#primary_menu ul li:hover a:visited{
color:#ea474b;
}
#menu-home-screen-menu{
margin-left:0;
}
}
Here is a fiddle: http://jsfiddle.net/x15jw967/
A few things help here. First, transition max-height instead of height to allow variation:
#primary_menu ul li ul {
...
max-height:0;
-webkit-transition: max-height 2s;
transition: max-height 2s;
}
#primary_menu ul li:hover ul {
...
max-height: 400px;
}
Then, set overflow to hidden so the outer content doesn't show:
#primary_menu ul li ul {
...
overflow: hidden;
}
Demo
Here's a simplified demo in which the close transition works also. You can add your styling back in and see what breaks it.
Can someone please help me? I'm trying to center my navigation menu. I have tried different things, but nothing works, and i really don't know what to do. I would really appreciate help. thanks in advance!
nav {
display: inline-block;
list-style-type: none;
float: left;
width: 100%;
height: 102px;
text-align: center;
}
nav > ul {
float:right;
width:100%;
height:102px;
background:#222;
border-radius: 10px 10px 0px 0px;
}
nav > ul > li {
float:left;
width:auto;
margin-right:10px;
line-height:102px;
}
nav > ul li a {
padding:50px;
color:white;
font-family:helvetica, sans-serif;
}
nav > ul > li > ul {
background:#222;
opacity:0;
transition:opacity 1s;
-webkit-transition:opacity 1s;
-moz-transition:opacity 1s;
-o-transition:opacity 1s;
-ms-transition:opacity 1s;
border-radius: 0px 0px 10px 10px;
}
nav > ul > li:hover > ul {
opacity:1;
}
HTML
<div>
<nav>
<ul>
<li> Hjem
<ul>
<li>Sub1</li>
<li>Sub2</li>
<li>Sub3</li>
</ul>
</li>
<li>Bilder</li>
<li>Video</li>
<li>Design</li>
</ul>
</nav>
</div>
Here is what I did.
#outer{
width:100%;
height: 102px;
text-align: center;
background:#222;
border-radius: 10px 10px 0px 0px;
}
nav {
display: inline-block;
list-style-type: none;
margin: 0 auto;
}
nav > ul > li {
float:left;
width:auto;
margin-right:10px;
line-height:102px;
}
nav > ul li a {
padding:50px;
color:white;
font-family:helvetica, sans-serif;
}
nav > ul > li > ul {
background:#222;
opacity:0;
transition:opacity 1s;
-webkit-transition:opacity 1s;
-moz-transition:opacity 1s;
-o-transition:opacity 1s;
-ms-transition:opacity 1s;
border-radius: 0px 0px 10px 10px;
}
nav > ul > li:hover > ul {
opacity:1;
}
And you just need to give an ID to the div.
<div id="outer">
this is sort of a continuation of this solved question.
as you can see in this fiddle the 3rd level dropdown is working but the fix has created this unexplainable single pixel transparent border at the bottom of the dropdowns. You can see it if you look closely between the dropdown and the box-shadow.
html:
<nav id="menu" class="dark_menu">
<!-- Main Nav Start -->
<ul id="main-nav" class="clearfix">
<li id="port" class="parent menu-item">Portfolio
<ul class="clearfix">
<li id="regular" class="parent menu-item">Regular
<ul class="clearfix">
<li id="menu-item-1036" class="menu-item">4 columns
</li>
<li id="menu-item-1033" class="menu-item">3 columns
</li>
<li id="menu-item-1030" class="menu-item">3 columns w/ sidebar
</li>
<li id="menu-item-1029" class="menu-item">2 columns
</li>
</ul>
</li>
<li id="2col" class="parent menu-item">Ajax
</li>
</ul>
</li>
<li id="menu-item-1727" class="parent menu-item">About
<ul class="clearfix">
<li id="menu-item-870" class="menu-item">Who We Are
</li>
<li id="menu-item-872" class="menu-item">What We Do
</li>
</ul>
</li>
</ul>
</nav>
css:
a {
text-decoration:none;
}
ul {
padding-left:0px;
}
#menu {
position:relative;
border:none;
height:auto;
top:34px;
left:0px;
}
#menu ul {
margin:0;
list-style:none;
}
#menu li {
float:left;
position:relative;
}
#menu > ul > li > a {
padding:25px 26px 17px;
border-bottom:3px solid transparent;
margin-right:1px;
color:#6B6B6B;
font:11px Arial, sans-serif;
font-weight:bold;
text-align:center;
text-transform:uppercase;
display:block;
}
#menu > ul > li:hover > a {
color:#F15A2B;
border-color:#F15A2B;
}
#menu > ul li.selected > a, #menu > ul li.selected:hover > a {
color:#3B3B3B;
border-color:#3B3B3B;
}
/* Submenu (second level) */
#menu li > ul {
position:absolute;
top:auto;
left:0;
width:180px;
max-height:0;
box-shadow:1px 2px 10px rgba(100, 100, 100, 0.3);
visibility: hidden;
z-index:99999;
overflow:hidden;
-webkit-transition: max-height 0.2s ease, visibility 0s linear 0.5s;
-moz-transition: max-height 0.2s ease, visibility 0s linear 0.5s;
-o-transition: max-height 0.2s ease, visibility 0s linear 0.5s;
-ms-transition: max-height 0.2s ease, visibility 0s linear 0.5s;
transition: max-height 0.2s ease, visibility 0s linear 0.5s;
background: inherit !important;
}
#menu ul li:hover > ul {
visibility: visible;
max-height: 216px;
transition-delay: 0s;
}
#menu ul li > ul:hover {
overflow:visible;
}
#menu li > ul li {
height:36px;
width:100%;
border-bottom:1px solid #EEE;
padding-top:0;
}
#menu li > ul li:last-child {
border-bottom:none;
}
#menu li > ul li a {
background:#FFF;
padding:11px 15px;
height:35px;
color:#999;
width:100%;
font:10px Arial, sans-serif;
font-weight:bold;
text-align:left;
text-transform:uppercase;
display:block;
}
#menu li > ul li:hover > a {
color:#FFF;
background:#F15A2B;
}
#menu li > ul li.selected > a, #menu li > ul li.selected:hover > a {
color:#3B3B3B;
background:#FFF;
}
/* Submenu (third level) */
#menu li > ul > li > ul {
position:absolute;
top:0 !important;
left:180px !important;
width:180px;
overflow:hidden;
box-shadow:1px 2px 10px rgba(100, 100, 100, 0.3);
visibility:hidden;
}
#menu li > ul > li:hover > ul {
visibility: visible;
}
#menu li > ul > li > ul > li:last-child {
border-bottom:none;
}
#menu li > ul li ul li a {
background:#FFF;
padding:11px 15px;
height:35px;
color:#999;
font:10px Arial, sans-serif;
font-weight:bold;
text-align:left;
text-transform:uppercase;
display:block;
}
#menu li > ul > li > ul > li:hover > a {
color:#FFF;
background:#F15A2B;
}
#menu li > ul li.selected > a, #menu li > ul li.selected:hover > a {
color:#3B3B3B;
background:#FFF;
}
/* Dark Menu */
#menu.dark_menu li ul li {
border-color:#464646;
}
#menu.dark_menu li ul li a {
background:#3B3B3B;
color:#999;
}
#menu.dark_menu li ul li:hover > a {
color:#FFF;
background:#F15A2B;
}
#menu.dark_menu li ul li.selected > a, #menu.dark_menu li ul li.selected:hover > a {
color:#FFF;
background:#3B3B3B;
}
* {
box-sizing:border-box;
-moz-box-sizing:border-box;
}
It looks like adding the following CSS below fixes your issue. If you want to remove the border on the last item, you have to make sure the element does not extend past its child height which is the only element with the background color.
#menu li > ul li:last-child {
border-bottom:none;
height: 35px;
}
I'm not sure if this can be done that way it was built but I'd like to add a transition effect to my dropdown. Anything that would make it seem less choppy. SLide, fade etc. Codepen below.
<div id="nav-wrap">
<ul>
<li id="link-one" class="orange">
<span>Test</span>
<div class="subnav">
<ul>
<li>Test</li>
<li>Test</li>
<li>Test</li>
<li>Test</li>
<li>Test</li>
<li>Test</li>
</ul>
</div><!-- /.subnav -->
</li>
<li class="red"><span>Test</span></li>
<li class="pink"><span>Test</span></li>
<li class="purple"><span>Test</span></li>
<li class="blue"><span>Test</span></li>
<li class="green"><span>Test</span></li>
<li class="yellow-facebook"><span></span></li>
</ul>
</div> <!-- nav-wrap -->
#nav-wrap .doubleLine {
display: table-cell;
line-height: 1.2em;
width:65.275%;
}
#nav-wrap {
width:100%;
height:100px;
font-weight:500;
padding: 0;
left:0;
font-family: 'Raleway', Arial, sans-serif;
z-index:100;
float:left;
}
#nav-wrap ul {
list-style-type: none;
margin: 0;
padding:0;
text-transform: uppercase;
}
#nav-wrap ul li {
width:14.275%; /* ~(100/7) */
display:block;
float:left;
text-align:center;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
#nav-wrap ul li + li {
border-left: 1px #fff solid !important;
}
#nav-wrap ul li a {
width:100%;
display: block;
height: 100%;
position: relative;
color:#FFFFFF !important;
text-decoration:none;
}
#nav-wrap ul li span {
display: inline-block;
vertical-align: middle;
height: 100px;
font-size:1.45em;
text-align: center;
padding: 0 5% 0 5%; /* was 0 20px */
line-height: 100px;
}
#nav-wrap ul li.yellow-facebook {
width:14.275%;
}
#nav-wrap ul li.yellow-facebook a {
background-size:130px 26px; /* > 25px */
}
li .subnav {
display: none;
/*position: absolute; */
clear: both;
margin-left: 0;
font-size:0.9em;
}
.subnav ul {
margin-left: 0;
float:left;
padding:0;
width:100%;
}
.subnav ul li {
margin: 0 0 0 0;
width:100% !important;
height:23px;
float:none !important;
}
.subnav ul li a {
padding: 10px 0 3px 0;
/*background-image: url(../images/submenu-background-divider.png);
background-repeat:no-repeat;
background-position:left;*/
}
#nav-wrap .subnav ul li + li {
border-left: none !important;
}
.subnav {
width:100%;
padding: 0;
margin: 0.05% 0 0 0;
border-top:#FFF 1px solid;
}
.subnav ul li a:link, a:active, a:visited {
text-decoration:none;
}
.subnav ul li a:hover {
color:#000;
text-decoration:none;
}
li:hover > .subnav {display:inline-block; left:0;}
#nav-wrap ul li.orange a {
background-color:#f37028;
}
#nav-wrap ul li.orange a:hover {
color: #231f20 !important;
}
#nav-wrap ul li.red a {
background-color:#ed1b24;
}
#nav-wrap ul li.red a:hover {
color: #231f20 !important;
}
#nav-wrap ul li.pink a {
background-color:#e54198;
}
#nav-wrap ul li.pink a:hover {
color: #231f20 !important;
}
#nav-wrap ul li.purple a {
background-color:#6b439c;
}
#nav-wrap ul li.purple a:hover {
color: #231f20 !important;
}
#nav-wrap ul li.blue a {
background-color:#0193cf;
}
#nav-wrap ul li.blue a:hover {
color: #231f20 !important;
}
#nav-wrap ul li.green a {
background-color:#80c02c;
}
#nav-wrap ul li.green a:hover {
color: #231f20 !important;
}
#nav-wrap ul li.yellow-facebook a {
background-color:#fff300;
background-image:url(../images/social-media/facebook-text.png);
background-repeat:no-repeat;
background-position:center;
}
#nav-wrap ul li.yellow-facebook a:hover {
color: #231f20;
background-image:url(../images/social-media/facebook-text_over.png);
}
http://codepen.io/Compton/pen/jLGyo/
You can try a CSS3 transition, only you would have to use opacity instead of display none.
add this
li:hover > .subnav {
display:inline-block;
left:0;
-webkit-transition: all 0.4s ease-in;
-moz-transition: all 0.4s ease-in;
-o-transition: all 0.4s ease-in;
transition: all 0.4s ease-in;
opacity:1.0;
}
and change the display none to this:
li .subnav {
opacity:0;
/*position: absolute; */
clear: both;
margin-left: 0;
font-size:0.9em;
}
Jquery can do some sliding if you'd rather, but this is a little simpler to set up, you can also adjust the height to make it slide down if youd rather that instead of a fade in.
Put this to the animated element CSS:
transform: translate3d(0, 0, 0);
-webkit-backface-visibility: hidden;
-webkit-perspective: 1000;
It basically fools browser that the transition or animation is 3D and enables GPU acceleration and disables two-sided planes in webkit based browsers.