I found below menu online and I like it, I want to change its width to 1400px. I tried to edit its CSS to match my header width for but I couldn't succeed.
Before I edit it
After I edit it
CSS Code
.nav,
.nav a,
.nav ul,
.nav li,
.nav div,
.nav form,
.nav input {
margin: 0;
padding: 0;
border: none;
outline: none;
width:100%; // What I have changed only
}
.nav a { text-decoration: none; }
.nav li { list-style: none; }
/* Menu Container */
.nav {
display: inline-block;
position: relative;
cursor: default;
z-index: 500;
}
/* Menu List */
.nav > li {
display: block;
float: left;
}
/* Menu Links */
.nav > li > a {
position: relative;
display: block;
z-index: 510;
height: 54px;
padding: 0 20px;
line-height: 54px;
font-family: Helvetica, Arial, sans-serif;
font-weight: bold;
font-size: 13px;
color: #fcfcfc;
text-shadow: 0 0 1px rgba(0,0,0,.35);
background: #771203;
border-left: 1px solid #4b4441;
border-right: 1px solid #312a27;
-webkit-transition: all .3s ease;
-moz-transition: all .3s ease;
-o-transition: all .3s ease;
-ms-transition: all .3s ease;
transition: all .3s ease;
}
.nav > li:hover > a { background: #4b4441; }
.nav > li:first-child > a {
border-radius: 3px 0 0 3px;
border-left: none;
}
/* Search Form */
.nav > li.nav-search > form {
position: relative;
width: inherit;
height: 54px;
z-index: 510;
border-left: 1px solid #4b4441;
}
.nav > li.nav-search input[type="text"] {
display: block;
float: left;
width: 1px;
height: 24px;
padding: 15px 0;
line-height: 24px;
font-family: Helvetica, Arial, sans-serif;
font-weight: bold;
font-size: 13px;
color: #999999;
text-shadow: 0 0 1px rgba(0,0,0,.35);
background: #771203;
-webkit-transition: all .3s ease 1s;
-moz-transition: all .3s ease 1s;
-o-transition: all .3s ease 1s;
-ms-transition: all .3s ease 1s;
transition: all .3s ease 1s;
}
.nav > li.nav-search input[type="text"]:focus { color: #fcfcfc; }
.nav > li.nav-search input[type="text"]:focus,
.nav > li.nav-search:hover input[type="text"] {
width: 110px;
padding: 15px 20px;
-webkit-transition: all .3s ease .1s;
-moz-transition: all .3s ease .1s;
-o-transition: all .3s ease .1s;
-ms-transition: all .3s ease .1s;
transition: all .3s ease .1s;
}
.nav > li.nav-search input[type="submit"] {
display: block;
float: left;
width: 20px;
height: 54px;
padding: 0 25px;
cursor: pointer;
background: #771203 url(../img/search-icon.png) no-repeat center center;
border-radius: 0 3px 3px 0;
-webkit-transition: all .3s ease;
-moz-transition: all .3s ease;
-o-transition: all .3s ease;
-ms-transition: all .3s ease;
transition: all .3s ease;
}
.nav > li.nav-search input[type="submit"]:hover { background-color: #4b4441; }
/* Menu Dropdown */
.nav > li > div {
position: absolute;
display: block;
width: 100%;
top: 50px;
left: 0;
opacity: 0;
visibility: hidden;
overflow: hidden;
background: #ffffff;
border-radius: 0 0 3px 3px;
-webkit-transition: all .3s ease .15s;
-moz-transition: all .3s ease .15s;
-o-transition: all .3s ease .15s;
-ms-transition: all .3s ease .15s;
transition: all .3s ease .15s;
}
.nav > li:hover > div {
opacity: 1;
visibility: visible;
overflow: visible;
}
/* Menu Content Styles */
.nav .nav-column {
float: left;
width: 20%;
padding: 2.5%;
}
.nav .nav-column h3 {
margin: 20px 0 10px 0;
line-height: 18px;
font-family: Helvetica, Arial, sans-serif;
font-weight: bold;
font-size: 14px;
color: #771203;
text-transform: uppercase;
}
.nav .nav-column h3.orange { color: #ff722b; }
.nav .nav-column li a {
display: block;
line-height: 26px;
font-family: Helvetica, Arial, sans-serif;
font-weight: bold;
font-size: 13px;
color: #888888;
}
.nav .nav-column li a:hover { color: #666666; }
Fiddle
My Probem
I want the menu items to be in an inline order(next to each other) just like the original menu but with 1400px or 100% width and menu the items are in the middle.
You can use display:flex for this purpose. Check the solution below, and here's the fiddle
.nav,
.nav a,
.nav ul,
.nav li,
.nav div,
.nav form,
.nav input {
margin: 0;
padding: 0;
border: none;
outline: none;
}
.nav a { text-decoration: none; }
.nav li { list-style: none; width:100%; }
/* Menu Container */
.nav {
display: flex;
position: relative;
cursor: default;
z-index: 500;
}
/* Menu List */
.nav > li {
float: left;
}
/* Menu Links */
.nav > li > a {
position: relative;
display: inline-flex;
width: 100%;
z-index: 510;
height: 54px;
padding: 0 20px;
line-height: 54px;
font-family: Helvetica, Arial, sans-serif;
font-weight: bold;
font-size: 13px;
color: #fcfcfc;
text-shadow: 0 0 1px rgba(0,0,0,.35);
background: #771203;
border-left: 1px solid #4b4441;
border-right: 1px solid #312a27;
-webkit-transition: all .3s ease;
-moz-transition: all .3s ease;
-o-transition: all .3s ease;
-ms-transition: all .3s ease;
transition: all .3s ease;
}
.nav > li:hover > a { background: #4b4441; }
.nav > li:first-child > a {
border-radius: 3px 0 0 3px;
border-left: none;
}
/* Search Form */
.nav > li.nav-search > form {
position: relative;
width: inherit;
height: 54px;
z-index: 510;
border-left: 1px solid #4b4441;
}
.nav > li.nav-search input[type="text"] {
display: block;
float: left;
width: 1px;
height: 24px;
padding: 15px 0;
line-height: 24px;
font-family: Helvetica, Arial, sans-serif;
font-weight: bold;
font-size: 13px;
color: #999999;
text-shadow: 0 0 1px rgba(0,0,0,.35);
background: #771203;
-webkit-transition: all .3s ease 1s;
-moz-transition: all .3s ease 1s;
-o-transition: all .3s ease 1s;
-ms-transition: all .3s ease 1s;
transition: all .3s ease 1s;
}
.nav > li.nav-search input[type="text"]:focus { color: #fcfcfc; }
.nav > li.nav-search input[type="text"]:focus,
.nav > li.nav-search:hover input[type="text"] {
width: 110px;
padding: 15px 20px;
-webkit-transition: all .3s ease .1s;
-moz-transition: all .3s ease .1s;
-o-transition: all .3s ease .1s;
-ms-transition: all .3s ease .1s;
transition: all .3s ease .1s;
}
.nav > li.nav-search input[type="submit"] {
display: block;
float: left;
width: 20px;
height: 54px;
padding: 0 25px;
cursor: pointer;
background: #771203 url(../img/search-icon.png) no-repeat center center;
border-radius: 0 3px 3px 0;
-webkit-transition: all .3s ease;
-moz-transition: all .3s ease;
-o-transition: all .3s ease;
-ms-transition: all .3s ease;
transition: all .3s ease;
}
.nav > li.nav-search input[type="submit"]:hover { background-color: #4b4441; }
/* Menu Dropdown */
.nav > li > div {
position: absolute;
display: block;
width: 100%;
top: 50px;
left: 0;
opacity: 0;
visibility: hidden;
overflow: hidden;
background: #ffffff;
border-radius: 0 0 3px 3px;
-webkit-transition: all .3s ease .15s;
-moz-transition: all .3s ease .15s;
-o-transition: all .3s ease .15s;
-ms-transition: all .3s ease .15s;
transition: all .3s ease .15s;
}
.nav > li:hover > div {
opacity: 1;
visibility: visible;
overflow: visible;
}
/* Menu Content Styles */
.nav .nav-column {
float: left;
width: 20%;
padding: 2.5%;
}
.nav .nav-column h3 {
margin: 20px 0 10px 0;
line-height: 18px;
font-family: Helvetica, Arial, sans-serif;
font-weight: bold;
font-size: 14px;
color: #771203;
text-transform: uppercase;
}
.nav .nav-column h3.orange { color: #ff722b; }
.nav .nav-column li a {
display: block;
line-height: 26px;
font-family: Helvetica, Arial, sans-serif;
font-weight: bold;
font-size: 13px;
color: #888888;
}
.nav .nav-column li a:hover { color: #666666; }
<div id="wrapper">
<div id="header"><img id="all" src="img/qa.png" alt="xxx"/></div>
<div id="menu-wrapper">
<ul class="nav">
<li>
Home
<div>
<div class="nav-column">
<h3>Home</h3>
<ul>
<li>Pampers Diapers</li>
<li>Huggies Diapers</li>
<li>Seventh Generation</li>
<li>Diapers</li>
<li>Derbies</li>
<li>Driving shoes</li>
<li>Espadrilles</li>
<li>Loafers</li>
</ul>
</div>
<div class="nav-column">
<h3>Home</h3>
<ul>
<li>Driving shoes</li>
<li>Espadrilles</li>
<li>Loafers</li>
</ul>
<h3>Home</h3>
<ul>
<li>Driving shoes</li>
<li>Espadrilles</li>
<li>Loafers</li>
</ul>
</div>
<div class="nav-column">
<h3>Home</h3>
<ul>
<li>Pampers Diapers</li>
<li>Huggies Diapers</li>
<li>Seventh Generation</li>
<li>Diapers</li>
<li>Derbies</li>
<li>Driving shoes</li>
<li>Espadrilles</li>
<li>Loafers</li>
</ul>
</div>
<div class="nav-column">
<h3 class="orange">Related Categories</h3>
<ul>
<li>Pampers Diapers</li>
<li>Huggies Diapers</li>
<li>Diapers</li>
</ul>
<h3 class="orange">Brands</h3>
<ul>
<li>Driving shoes</li>
<li>Espadrilles</li>
</ul>
</div>
</div>
</li>
<li>MOE</li>
<li>
EEC-SEAA
<div>
<div class="nav-column">
<h3 class="orange">Related Categories</h3>
<ul>
<li>Pampers Diapers</li>
<li>Huggies Diapers</li>
<li>Diapers</li>
</ul>
<h3 class="orange">Brands</h3>
<ul>
<li>Driving shoes</li>
<li>Espadrilles</li>
</ul>
</div>
<div class="nav-column">
<h3>Home</h3>
<ul>
<li>Pampers Diapers</li>
<li>Huggies Diapers</li>
<li>Seventh Generation</li>
<li>Diapers</li>
<li>Derbies</li>
<li>Driving shoes</li>
<li>Espadrilles</li>
<li>Loafers</li>
</ul>
</div>
<div class="nav-column">
<h3>Home</h3>
<ul>
<li>Driving shoes</li>
<li>Espadrilles</li>
<li>Loafers</li>
</ul>
<h3>Home</h3>
<ul>
<li>Driving shoes</li>
<li>Espadrilles</li>
<li>Loafers</li>
</ul>
</div>
<div class="nav-column">
<h3>Home</h3>
<ul>
<li>Pampers Diapers</li>
<li>Huggies Diapers</li>
<li>Seventh Generation</li>
<li>Diapers</li>
<li>Derbies</li>
<li>Driving shoes</li>
<li>Espadrilles</li>
<li>Loafers</li>
</ul>
</div>
</div>
</li>
<li>About Us</li>
<li>Our Achievements</li>
<li class="nav-search">
<form action="#">
<input type="text" placeholder="Search...">
<input type="submit" value="">
</form>
</li>
</ul>
</div>
</div>
Related
I thought it would have been simple, I'm trying to make a small navigation with numbers which show a name below on hover which should be like this :
But I don't know how to keep it centered and without having big margins between numbers. Here is a JSFiddle
.dropdown {
font-size: 10pt;
width: 10px;
}
nav ul {
font-size: 0;
list-style: none;
margin: 0;
padding: 0;
text-align: center;
width: 100%;
}
nav li {
display: inline-block;
margin: 0;
padding: 0;
position: relative;
width: auto;
}
nav a {
color: #444;
display: block;
padding: 0 25px;
text-align: center;
text-decoration: none;
-webkit-transition: all .25s ease;
-moz-transition: all .25s ease;
-ms-transition: all .25s ease;
-o-transition: all .25s ease;
transition: all .25s ease;
}
nav li ul {
font-size: 10pt;
height: 20px;
left: 0;
opacity: 0;
position: absolute;
top: 35px;
visibility: hidden;
z-index: 1;
-webkit-transition: all .25s ease;
-moz-transition: all .25s ease;
-ms-transition: all .25s ease;
-o-transition: all .25s ease;
transition: all .25s ease;
}
nav li:hover ul {
opacity: 1;
top: 50px;
visibility: visible;
}
nav li ul li {
width: 100%;
}
nav li ul a {
background: #bbb;
}
Here the result thanks to #Ovakuro : JSFiddle
Here is a solution to your layout using flexbox. I've simplified your CSS quite a bit, let me know if you have any questions.
nav .cf,
.dropdown {
list-style: none;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
}
nav .cf li {
position: relative;
}
nav .cf li a {
color: #444;
padding: 0 10px;
text-decoration: none;
}
nav .cf li:hover .dropdown {
opacity: 1;
visibility: visible;
}
/* style your dropdown menu here */
.dropdown {
width: 100%;
list-style: none;
font-size: 10pt;
position: absolute;
top: 30px;
opacity: 0;
visibility: hidden;
z-index: 1;
-webkit-transition: all .25s ease;
-moz-transition: all .25s ease;
-ms-transition: all .25s ease;
-o-transition: all .25s ease;
transition: all .25s ease;
}
.dropdown li {
display: flex;
}
nav .cf .dropdown li a {
padding: 10px 20px;
background: #bbb;
text-align: center;
white-space: nowrap;
}
/* triangle */
.dropdown:after {
bottom: 100%;
content: " ";
position: absolute;
border: solid transparent;
border-bottom-color: #bbb;
border-width: 10px;
}
<nav>
<ul class="cf">
<li>
01
<ul class="dropdown">
<li>E-CAMPUS</li>
</ul>
</li>
<li>
02
<ul class="dropdown">
<li>PEGASEZBUZZ</li>
</ul>
</li>
</ul>
</nav>
To my knowledge, the only way to do this is to set a width to the ul children so you can center it after. It's necessary if you need to go beyond parents' width.
I use transform translate, but if you need to be fully backward compatible, you would do this in js. Also, you may have problems with screen sides this way, again, js is your friend.
Note : I added /* new */ in css so you can see what I did. ;) Cheers
.dropdown {
font-size: 10pt;
width: 10px;
}
nav ul {
font-size: 0;
list-style: none;
margin: 0;
padding: 0;
text-align: center;
width: 100%;
position: relative; /* new */
}
nav li {
display: inline-block;
margin: 0;
padding: 0;
position: relative;
width: auto;
}
nav a {
color: #444;
display: block;
padding: 1em;
text-align: center;
text-decoration: none;
-webkit-transition: all .25s ease;
-moz-transition: all .25s ease;
-ms-transition: all .25s ease;
-o-transition: all .25s ease;
transition: all .25s ease;
}
nav li ul {
font-size: 10pt;
height: 20px;
left: 0;
opacity: 0;
position: absolute;
top: 35px;
visibility: hidden;
z-index: 1;
-webkit-transition: all .25s ease;
-moz-transition: all .25s ease;
-ms-transition: all .25s ease;
-o-transition: all .25s ease;
transition: all .25s ease;
left: 50%; /* new */
transform: translateX(-50%); /* new */
width: 200px; /* new */
}
nav li:hover ul {
opacity: 1;
top: 50px;
visibility: visible;
}
nav li ul li {
width: 100%;
}
nav li ul a {
background: #bbb;
}
<nav>
<ul class="cf">
<li><a class="dropdown" href="#">01</a>
<ul>
<li>E-CAMPUS</li>
</ul>
</li>
<li><a class="dropdown" href="#">02</a>
<ul>
<li>PEGASEZBUZZ</li>
</ul>
</li>
</ul>
</nav>
Is this close to what you wanted?
body {
background-color: black;
}
.dropdown {
font-size: 20pt;
width: 10px;
}
nav ul {
font-size: 0;
list-style: none;
margin: 0;
padding: 0;
text-align: center;
width: 100%;
}
nav li {
display: inline-block;
margin: 0;
padding: 0;
position: relative;
width: auto;
}
nav a {
color: gray;
display: block;
padding: 0 25px;
text-align: center;
text-decoration: none;
-webkit-transition: all .25s ease;
-moz-transition: all .25s ease;
-ms-transition: all .25s ease;
-o-transition: all .25s ease;
transition: all .25s ease;
}
nav li ul {
font-size: 10pt;
height: 20px;
left: 0;
opacity: 0;
position: absolute;
top: 35px;
visibility: hidden;
z-index: 1;
-webkit-transition: all .25s ease;
-moz-transition: all .25s ease;
-ms-transition: all .25s ease;
-o-transition: all .25s ease;
transition: all .25s ease;
}
nav li:hover ul {
opacity: 1;
top: 50px;
visibility: visible;
margin-top: -10px;
}
nav li ul li {
width: 100%;
}
nav li:hover ul:before {
content: "";
position: absolute;
bottom: -10px;
border-style: solid;
border-color: #EDEDED transparent;
display: block;
top: -8px;
bottom: auto;
right: 15px;
border-width: 0 10px 10px;
}
nav li ul a {
background: #EDEDED;
width: 100px;
margin-left: -25px;
margin-bottom: 100px;
padding: 10px;
color: #0050F7;
}
.dropdown:hover {
color: white;
}
<nav>
<ul class="cf">
<li><a class="dropdown" href="#">01</a>
<ul>
<li>E-CAMPUS</li>
</ul>
</li>
<li><a class="dropdown" href="#">02</a>
<ul>
<li>PEGASEZBUZZ</li>
</ul>
</li>
</ul>
</nav>
Or if you want your hover tags always centered you may use this:
body {
margin: 0;
padding: 0;
}
.container {
background-color: black;
width: 500px;
height: 300px;
}
ul {
list-style: none;
color: #666;
font-size: 30px;
margin: 0;
padding: 0;
text-align: center;
padding-top: 20px;
position:relative;
}
ul li {
display: inline-block;
padding: 0 12px;
}
.hover {
position:absolute;
top:70px;
text-align:center;
width:100%;
left:0;
display:none;
}
.hover span {
display: inline-block;
background-color:#fff;
color:blue;
font-size:30px;
padding:12px 20px;
}
li:hover {color:#bbb;}
li:hover .hover {display:block;}
.hover:before {
content:"";
display:inline-block;
width: 0;
height: 0;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-bottom: 5px solid #fff;
padding:0;
position:absolute;
top:-5px;
}
.hv1:before {left:154px;}
.hv2:before {left:214px;}
.hv3:before {left:278px;}
.hv4:before {left:340px;}
<div class="container">
<ul>
<li>01
<div class="hover hv1"><span>This is the first 1</span></div>
</li>
<li>02
<div class="hover hv2"><span>Tag2 here</span></div>
</li>
<li>03
<div class="hover hv3 "><span>Tag3 much much longer</span></div>
</li>
<li>04
<div class="hover hv4 "><span>Tag4</span></div>
</li>
</ul>
</div>
Notice you need a text covering enough room for the arrow to show
I have a simple question. I am trying to add a fade-in effect to the submenus like in this page but I don't really understand the ul li ul selectors concept well and so it is not coming out correct.,
It doesn't seem really difficult but I am doing something wrong which I can't figure out!!
How can I add this CSS transition effect? I have tried using the animate.css library but usage of the library is not mandatory and I am OK with a solution which doesn't use it also.
.classname li:hover > ul{
display:block;
-moz-animation: fadeInUp .3s ease-in ;
-webkit-animation: fadeInUp .3s ease-in ;
animation:fadeInUp .3s ease-in ;
}
.classname ul li:hover > ul{
display:block;
-moz-animation: fadeInRight .3s ease-in ;
-webkit-animation: fadeInRight .3s ease-in ;
animation:fadeInRight .3s ease-in ;
}
Demo: Below is a snippet which has my current coding attempt.
/* MENU NAVIGATION */
#nav span {
display: none;
}
#nav,
#nav ul {
list-style: none outside none;
margin: 0;
padding: 0;
}
#nav {
font-family: 'Josefin Sans', sans-serif;
float: left;
margin-left: 1%;
margin-right: 1%;
position: relative;
width: 98%;
}
#nav ul.subs {
background-color: #FFFFFF;
box-shadow: 1px 1px 5px rgba(0, 0, 0, 0.2);
color: #333333;
display: none;
left: 0;
padding: 2%;
position: absolute;
top: 54px;
width: 96%;
}
#nav > li {
border-bottom: 5px solid transparent;
float: left;
margin-bottom: -5px;
text-align: left;
-moz-transition: all 300ms ease-in-out 0s;
-ms-transition: all 300ms ease-in-out 0s;
-o-transition: all 300ms ease-in-out 0s;
-webkit-transition: all 300ms ease-in-out 0s;
transition: all 300ms ease-in-out 0s;
}
#nav li a {
display: block;
text-decoration: none;
-moz-transition: color 450ms ease-in-out 0s, background-color 450ms ease-in-out 0s;
-ms-transition: color 450ms ease-in-out 0s, background-color 450ms ease-in-out 0s;
-o-transition: color 450ms ease-in-out 0s, background-color 450ms ease-in-out 0s;
-webkit-transition: color 450ms ease-in-out 0s, background-color 450ms ease-in-out 0s;
transition: color 450ms ease-in-out 0s, background-color 450ms ease-in-out 0s;
white-space: normal;
}
#nav > li > a {
color: #333333;
display: block;
line-height: 49px;
padding: 0 15px;
text-transform: uppercase;
}
#nav > li:hover > a,
#nav > a:hover {
background-color: #F55856;
color: #FFFFFF;
}
#nav li.active > a {
background-color: #333333;
color: #FFFFFF;
}
/* submenu */
#nav li:hover ul.subs {
display: block;
}
#nav ul.subs > li {
display: inline-block;
float: none;
padding: 10px 1%;
vertical-align: top;
width: 33%;
}
#nav ul.subs > li a {
color: #777777;
line-height: 20px;
}
#nav ul li a:hover {
color: #F55856;
}
#nav ul.subs > li > a {
font-size: 1.3em;
margin-bottom: 10px;
text-transform: uppercase;
}
#nav ul.subs > li li {
float: none;
padding-left: 8px;
-moz-transition: padding 150ms ease-out 0s;
-ms-transition: padding 150ms ease-out 0s;
-o-transition: padding 150ms ease-out 0s;
-webkit-transition: padding 150ms ease-out 0s;
transition: padding 150ms ease-out 0s;
}
#nav ul.subs > li li:hover {
padding-left: 15px;
}
<div class="container">
<ul id="nav">
<li>Home
</li>
<li>Prodotti
<span id="s1"></span>
<ul class="subs">
<li>Header a
<ul>
<li>Submenu x
</li>
<li>Submenu y
</li>
<li>Submenu z
</li>
</ul>
</li>
<li>Header b
<ul>
<li>Submenu x
</li>
<li>Submenu y
</li>
<li>Submenu z
</li>
</ul>
</li>
</ul>
</li>
<li>Shop
</li>
<li>Area Privata
</li>
<li>Contatti
</li>
</ul>
</div>
There is no need for an animation or a separate library to achieve the effect that you need. These can be achieved by just using transitions and some CSS transforms.
Demo: (explanation is provided below).
/* MENU NAVIGATION */
#nav span {
display: none;
}
#nav,
#nav ul {
list-style: none outside none;
margin: 0;
padding: 0;
}
#nav {
font-family: 'Josefin Sans', sans-serif;
float: left;
margin-left: 1%;
margin-right: 1%;
position: relative;
width: 98%;
}
#nav ul.subs {
background-color: #FFFFFF;
box-shadow: 1px 1px 5px rgba(0, 0, 0, 0.2);
color: #333333;
left: 0;
padding: 2%;
position: absolute;
top: 54px;
width: 96%;
}
#nav > li {
border-bottom: 5px solid transparent;
float: left;
margin-bottom: -5px;
text-align: left;
transition: all 300ms ease-in-out 0s;
}
#nav li a {
display: block;
text-decoration: none;
transition: color 450ms ease-in-out 0s, background-color 450ms ease-in-out 0s;
white-space: normal;
}
#nav > li > a {
color: #333333;
display: block;
line-height: 49px;
padding: 0 15px;
text-transform: uppercase;
}
#nav > li:hover > a,
#nav > a:hover {
background-color: #F55856;
color: #FFFFFF;
}
#nav li.active > a {
background-color: #333333;
color: #FFFFFF;
}
/* submenu */
#nav ul.subs > li {
display: inline-block;
float: none;
padding: 10px 1%;
vertical-align: top;
width: 33%;
}
#nav ul.subs > li a {
color: #777777;
line-height: 20px;
}
#nav ul li a:hover {
color: #F55856;
}
#nav ul.subs > li > a {
font-size: 1.3em;
margin-bottom: 10px;
text-transform: uppercase;
}
#nav ul.subs > li li {
float: none;
padding-left: 8px;
transition: padding 150ms ease-out 0s;
}
#nav ul.subs > li li:hover {
padding-left: 15px;
}
#nav > li > ul {
opacity: 0;
transform: translateY(25%);
transition: all 150ms ease;
pointer-events: none;
}
#nav > li:hover > ul {
opacity: 1;
transform: translateY(0%);
pointer-events: auto;
}
#nav > li > ul > li > ul {
opacity: 0;
transform: translateX(50%);
transition: all 150ms ease;
}
#nav > li > ul > li:hover > ul {
opacity: 1;
transform: translateX(0%);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
<div class="container">
<ul id="nav">
<li>Home
</li>
<li>Prodotti
<span id="s1"></span>
<ul class="subs">
<li>Header a
<ul>
<li>Submenu x
</li>
<li>Submenu y
</li>
<li>Submenu z
</li>
</ul>
</li>
<li>Header b
<ul>
<li>Submenu x
</li>
<li>Submenu y
</li>
<li>Submenu z
</li>
</ul>
</li>
</ul>
</li>
<li>Shop
</li>
<li>Area Privata
</li>
<li>Contatti
</li>
</ul>
</div>
Code Explained:
In order to produce an effect similar to that in the page which you linked (that is, the 1st level submenu does a fade-in + move up on hover and the 2nd level sub-menu does a fade-in + move left on hover), the following things need to be done:
Currently you are toggling the display property of the ul that contains the first level submenu when hovering on PRODOTTI. But change of value to the display property is not transitionable and because of this the submenu will appear in an instant. Just remove the lines that cause this.
#nav ul.subs {
background-color: #FFFFFF;
box-shadow: 1px 1px 5px rgba(0, 0, 0, 0.2);
color: #333333;
/*display: none; comment out or remove this line */
left: 0;
padding: 2%;
position: absolute;
top: 54px;
width: 96%;
}
/* remove these */
#nav li:hover ul.subs {
display: block;
}
After that set the initial state of the ul that contains the submenu to have opacity: 1 and also add transform: translateY(25%) to it. This will push the submenu's container down by 25% of its height.
#nav > li > ul{
opacity: 0;
transform: translateY(25%);
transition: all 150ms ease;
pointer-events: none;
}
When the PRODOTTI link is hovered, change the submenu's opacity to 1 and translate it back to its original position by setting `transform: translateY(0%). This makes it look as though the submenu is fading-in and is moving up at the same time.
#nav > li:hover > ul{
opacity: 1;
transform: translateY(0%);
pointer-events: auto;
}
For the second level submenu, the same steps are followed except that instead of using translateY, we are using translateX because it has to be moved to the right and not down.
#nav > li > ul > li > ul{
opacity: 0;
transform: translateX(50%);
transition: all 150ms ease;
}
#nav > li > ul > li:hover > ul{
opacity: 1;
transform: translateX(0%);
}
The padding around the link for my dropdown menu isn't clickable. When I mouse over the actual text, it changes color and becomes clickable. How can I make the padding clickable? I read that I should style it as an inline-block, but that didn't work. This is also my first post, so correct me for the countless things that I probably did wrong.
CSS:
body {
font-family: 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, sans-serif;
padding: 20px 50px 150px;
font-size: 13px;
text-align: left;
background-position:center;
background-image:url(sun.jpg);
}
a {
display:inline-block;
color: #6FF;
text-decoration: none;
}
a:hover {
color: #FFF;
}
ul {
color:#6FF
text-align: left;
display: inline-block;
margin: 0;
padding: 1px 1px 1px 0;
list-style: none;
}
ul li {
color: purple;
font: bold 12px/18px sans-serif;
display: inline-block;
margin-right: -10px;
position: relative;
padding: 20px 20px;
background: #fff;
cursor: pointer;
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
-ms-transition: all 0.5s;
-o-transition: all 0.5s;
transition: all 0.5s;
}
ul li:hover {
background: #555;
color: #fff;
}
ul li ul {
padding:0;
position:absolute;
top: 54px;
left: 0;
width: 150px;
display: none;
opacity: 0;
visibility: hidden;
-webkit-transiton: opacity 0.5s;
-moz-transition: opacity 0.5s;
-ms-transition: opacity 0.5s;
-o-transition: opacity 0.5s;
-transition: opacity 0.5s;
}
ul li ul li {
background-color:#555;
color:#6FF;
display: block;
}
ul li ul li:hover { background: #555; }
ul li:hover ul {
display: block;
opacity: 1;
visibility: visible;
}
You should put the padding to the link, no the list item because the link is what is clickable.
body {
font-family:'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, sans-serif;
padding: 20px 50px 150px;
font-size: 13px;
text-align: left;
background-position:center;
background-image:url(sun.jpg);
}
a {
padding: 20px 20px;
display:inline-block;
color: #6FF;
text-decoration: none;
}
a:hover {
color: #FFF;
}
ul {
color:#6FF text-align: left;
display: inline-block;
margin: 0;
padding: 1px 1px 1px 0;
list-style: none;
}
ul li {
color: purple;
font: bold 12px/18px sans-serif;
display: inline-block;
margin-right: -10px;
position: relative;
background: #fff;
cursor: pointer;
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
-ms-transition: all 0.5s;
-o-transition: all 0.5s;
transition: all 0.5s;
}
ul li:hover {
background: #555;
color: #fff;
}
ul li ul {
padding:0;
position:absolute;
top: 54px;
left: 0;
width: 150px;
display: none;
opacity: 0;
visibility: hidden;
-webkit-transiton: opacity 0.5s;
-moz-transition: opacity 0.5s;
-ms-transition: opacity 0.5s;
-o-transition: opacity 0.5s;
-transition: opacity 0.5s;
}
ul li ul li {
background-color:#555;
color:#6FF;
display: block;
}
ul li ul li:hover {
background: #555;
}
ul li:hover ul {
display: block;
opacity: 1;
visibility: visible;
}
<ul>
<li>First link
</li>
<li>First link
</li>
<li>First link
</li>
<li>First link
</li>
<li>First link
</li>
<li>First link
</li>
</ul>
I've got a side navigation with the items flying out when they are hovered. Now I've added a second level to the navigation. The problem is that the li a with sub-items fly only out when a sub-link is hovered.
Possible scenarios:
Parent with child hovered: parent flies out
Child hovered: child flies out (but not parent)
Parent without child hovered: parent flies out
Here is a JSBin of what I mean:
http://jsbin.com/zusoyeweqa/edit?html,css,js,output
How can I have only the list-element selected fly transitioned?
This is the HTML:
<nav id="site-navigation" role="navigation">
<ul class="side-nav">
<li>Blog
<ul>
<li>Sub Link 1</li>
<li>Sub Link 2</li>
</ul>
</li>
<li>Tools</li>
</ul>
</nav>
This is the CSS
#site-navigation ul>li{
font-size: 1.6em;
width: auto;
float: right;
display: block;
clear: both;
line-height: 1em;
margin-bottom: 1px;
}
#site-navigation ul>li a{
-webkit-transition: all 0.3s ease-in-out;
-transition: all 0.3s ease-in-out;
-webkit-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
font-family: "Oswald",Arial,sans-serif;
text-transform: uppercase;
background: #FFF;
color: #000;
padding: .25em;
width: auto;
}
#site-navigation ul>li a:hover{
background: #c00;
color: #fff;
padding-right: 1em;
}
#site-navigation ul>li>ul>li a {
color: #FFF;
background: none;
}
EDIT: Added a jsbin http://jsbin.com/zusoyeweqa/edit?html,css,js,output
I hope this helps ..
replace yous css with following
#site-navigation .side-nav>li{
font-size: 1.6em;
width: auto;
float: right;
display: block;
clear: both;
line-height: 1em;
margin-bottom: 1px;
}
#site-navigation .side-nav>li a{
-webkit-transition: all 0.3s ease-in-out;
-transition: all 0.3s ease-in-out;
-webkit-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
font-family: "Oswald",Arial,sans-serif;
text-transform: uppercase;
background: #FFF;
color: #000;
padding: .25em;
width: auto;
position:relative;
}
#site-navigation ul>li a:hover{
background: #c00;
color: #fff;
right: 1em;
}
#site-navigation ul>li a:hover .{
background: #c00;
color: #fff;
right: 1em;
}
You can use position relative and right to fly only the selected item out.
#site-navigation .side-nav>li{
font-size: 1.6em;
width: auto;
float: right;
display: block;
clear: both;
line-height: 1em;
margin-bottom: 1px;
}
#site-navigation .side-nav>li a{
-webkit-transition: all 0.3s ease-in-out;
-transition: all 0.3s ease-in-out;
-webkit-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
font-family: "Oswald",Arial,sans-serif;
text-transform: uppercase;
background: #FFF;
color: #000;
padding: .25em;
width: auto;
/* Use position relative and right to fly out. */
position: relative;
right: 0;
}
#site-navigation ul>li a:hover{
background: #c00;
color: #fff;
/* Use right to fly out. */
right: 1em;
}
For some reason, I hover over the area below the main navigation tabs and it brings up the drop down menu. I've been trying to figure this out and I'm trying to avoid writing it from the beginning.
Any help?
Here's the CSS code I have:
#primary_nav_wrapper {
position: relative;
top: 85px;
width: 100%;
height: 39px;
border-top: 1px solid rgb(90,90,90);
}
#primary_nav {
position: absolute;
margin: 0 2.5%;
width: 95%;
height: 100%;
}
/* Affects parent tabs only ============================================================================*/
#primary_nav > ul#all_parent_tabs {
position: relative;
margin: 0;
/* ^ Resets margin for the parent tabs in th primary nav. Removing affects position*/
padding: 0;
/* ^ Resets padding for the parent tabs in th primary nav. Removing affects position*/
height: 100%;
/*Sets ul*/
list-style-type: none;
text-align: center;
font-size: 14px;
}
#primary_nav > ul#all_parent_tabs > li {
position: relative;
float: left;
list-style-type: none;
width: 12.5%;
height: 100%;
display: block;
-webkit-transition: all .3s;
-moz-transition: all .3s;
-ms-transition: all .3s;
-o-transition: all .3s;
transition: all .3s;
}
#primary_nav > ul#all_parent_tabs > li > a {
display: block;
text-decoration: none;
color: rgb(133,133,133);
}
#primary_nav > ul#all_parent_tabs > li.parent_tabs_one_line > a{
line-height: 39px;
}
#primary_nav > ul#all_parent_tabs > li.parent_tabs_two_line > a{
padding: 4px 0 0 0;
}
#primary_nav > ul#all_parent_tabs > li:hover {
background-color: rgb(248,248,248);
-webkit-transition: all .3s;
-moz-transition: all .3s;
-ms-transition: all .3s;
-o-transition: all .3s;
transition: all .3s;
}
#primary_nav > ul#all_parent_tabs > li:hover > ul.drop_down_menu li a{
visibility: visible;
opacity: 1;
-webkit-transition: .4s all .4s;
-moz-transition: .4s all .4s;
-ms-transition: .4s all .4s;
-o-transition: .4s all .4s;
transition: .4s all .4s;
}
#primary_nav > ul#all_parent_tabs > li#active_tab {
border-bottom: 3px solid rgb(65,217,28);
background-color: rgb(248,248,248);
box-sizing:border-box;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
-ms-box-sizing:border-box;
-o-box-sizing:border-box;
}
/* For drop-down menu ==================================================================================*/
#primary_nav > ul#all_parent_tabs > li > ul.drop_down_menu {
position: absolute;
margin: 0;
padding: 0;
height: 262px;
width: 140%;
top: 39px;
text-align: left;
}
#primary_nav > ul#all_parent_tabs > li > ul.drop_down_menu > li {
margin: 0;
padding: 0;
width: 140%;
height: 26px;
line-height: 26px;
font-size: 13px;
display: block;
}
#primary_nav ul#all_parent_tabs > li > ul.drop_down_menu > li > a{
position: absolute;
margin: 0;
padding: 0 5px;
display: block;
width: 140%;
background-color: rgb(240,240,240);
border: 1px solid rgb(205,205,205);
text-decoration: none;
color: rgb(150,150,150);
z-index: 1;
visibility: hidden;
opacity: 0;
}
#primary_nav ul#all_parent_tabs > li:hover > ul.drop_down_menu > li > a:hover {
background-color: rgb(233,254,237);
-webkit-transition: all .2s;
-moz-transition: all .2s;
-ms-transition: all .2s;
-o-transition: all .2s;
transition: all .2s;
The issue is to do with the fact that ul.drop_down_menu is not set to hidden, but rather its child elements (a tags). For this reason, hovering over ul.drop_down_menu still triggers the hover state of its parent li tag (which is what triggers your transitions).
Adding this solves the problem:
ul.drop_down_menu {
visibility:hidden;
}
li:hover ul.drop_down_menu {
visibility:visible;
}
JSFiddle