一些 href 链接没有响应
Some href links are not responding
我正在制作菜单,但是 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>
尝试 links 使用 [ctrl + click] 测试 links
"Search" 框 正在工作 ,但是如果您单击 "Extras" --> "Instructions",则没有任何反应。
我认为 Extra 的 中的 link 阻止了它的工作。
但是如果没有“Extras”作为 link,菜单将不会展开。
添加到您的 css
.nav-content:hover{
max-height:400px;
}
因为 nav-content 的最大高度只有 400px,当聚焦 .nav-item 时,如果您点击其他站点,.nav-content 会丢失 max-height 而您没有点击 link
添加此规则,使元素可点击:
.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;
}
这是因为,您在 focus
上分配了事件,当您尝试点击 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>
我正在制作菜单,但是 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>
尝试 links 使用 [ctrl + click] 测试 links
"Search" 框 正在工作 ,但是如果您单击 "Extras" --> "Instructions",则没有任何反应。
我认为 Extra 的 中的 link 阻止了它的工作。 但是如果没有“Extras”作为 link,菜单将不会展开。
添加到您的 css
.nav-content:hover{
max-height:400px;
}
因为 nav-content 的最大高度只有 400px,当聚焦 .nav-item 时,如果您点击其他站点,.nav-content 会丢失 max-height 而您没有点击 link
添加此规则,使元素可点击:
.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;
}
这是因为,您在 focus
上分配了事件,当您尝试点击 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>