I am making a menu, but I have a problem with a link.
body,html{
margin:0;
font:1em "open sans",sans-serif;
}
/**************/
/* MENU BAR */
/**************/
.nav-main{
width:100%;
background-color:#222;
height:70px;
color:#fff;
padding-left: 33%;
padding-right: 33%;
}
.nav-main > ul{
margin:0;
padding:0;
float:left;
list-style-type:none;
}
.nav-main > ul > li{
float:left;
}
.nav-item{
display:inline-block;
padding:15px 20px;
height:40px;
line-height:40px;
color:#fff;
text-decoration:none;
}
.nav-item:hover {
background-color:#444;
}
.nav-content{
position:absolute;
top:70px;
overflow:hidden;
background-color:#222;
max-height:0;
}
.nav-content a{
color:#fff;
text-decoration:none;
}
.nav-content a:hover{
text-decoration:underline;
}
.nav-sub{
padding:20px;
}
.nav-sub ul{
padding:0;
margin:0;
list-style-type:none;
}
.nav-sub ul li a{
display:inline-block;
padding:5px 0;
}
.nav-item:focus{
background-color:#444;
}
.nav-item:focus ~ .nav-content{
max-height:400px;
-webkit-transition:max-height 400ms ease-in;
-moz-transition:max-height 400ms ease-in;
transition:max-height 400ms ease-in;
}
<nav class="nav-main">
<ul>
<li>
<a href="http://www.google.com" class="nav-item">Search</a>
</li>
<li>
<a href="#" class="nav-item">Extra's</a>
<div class="nav-content">
<div class="nav-sub">
<ul>
<li><a href="http://www.google.com">Instructions</a> </li>
</ul>
</div>
</div>
</li>
</ul>
</nav>
try the links using [ctrl + click] to test the links
The "Search" box is working, but if you click on "Extras" --> "Instructions", nothing is happening.
I think that the link in Extra's is preventing it to work. But without the "Extras" as a link, the menu wont expand.
Add this rule, so that the element is clickable:
.nav-item:focus ~ .nav-content,
.nav-content:hover {
max-height:400px;
-webkit-transition:max-height 400ms ease-in;
-moz-transition:max-height 400ms ease-in;
transition:max-height 400ms ease-in;
}
It is because, you have assigned the event on the focus
, it goes off when you try to click on the link.
body,html{
margin:0;
font:1em "open sans",sans-serif;
}
/**************/
/* MENU BAR */
/**************/
.nav-main{
width:100%;
background-color:#222;
height:70px;
color:#fff;
padding-left: 33%;
padding-right: 33%;
}
.nav-main > ul{
margin:0;
padding:0;
float:left;
list-style-type:none;
}
.nav-main > ul > li{
float:left;
}
.nav-item{
display:inline-block;
padding:15px 20px;
height:40px;
line-height:40px;
color:#fff;
text-decoration:none;
}
.nav-item:hover {
background-color:#444;
}
.nav-content{
position:absolute;
top:70px;
overflow:hidden;
background-color:#222;
max-height:0;
}
.nav-content a{
color:#fff;
text-decoration:none;
}
.nav-content a:hover{
text-decoration:underline;
}
.nav-sub{
padding:20px;
}
.nav-sub ul{
padding:0;
margin:0;
list-style-type:none;
}
.nav-sub ul li a{
display:inline-block;
padding:5px 0;
}
.nav-item:focus{
background-color:#444;
}
.nav-item:focus ~ .nav-content, .nav-content:hover {
max-height:400px;
-webkit-transition:max-height 400ms ease-in;
-moz-transition:max-height 400ms ease-in;
transition:max-height 400ms ease-in;
}
<nav class="nav-main">
<ul>
<li>
<a href="http://www.google.com" class="nav-item">Search</a>
</li>
<li>
<a href="#" class="nav-item">Extra's</a>
<div class="nav-content">
<div class="nav-sub">
<ul>
<li><a href="http://www.google.com">Instructions</a> </li>
</ul>
</div>
</div>
</li>
</ul>
</nav>