【发布时间】:2015-07-16 00:00:37
【问题描述】:
我一直在为jsfiddle 找到的导航菜单使用 CSS 过渡。相同的代码可以在下面找到:
CSS:
nav {
background-color: #337AB7;
position: relative;
}
nav:after {
display: table;
content: '';
clear: both;
}
nav h1 {
float: left;
margin: 0;
}
nav #nav-toggle {
display: none;
}
nav label[for='nav-toggle']:after {
float: right;
display: block;
padding: .5em;
margin: .5em;
width: 4em;
content: 'Menu';
text-align: center;
color: #fff;
border: 1px solid #fff;
border-radius: 3px;
}
nav ul {
float: left;
display: block;
margin: 0;
padding: 0;
list-style: none;
width: 100%;
max-height: 0;
overflow: hidden;
transition: max-height 1s ease;
}
nav #nav-toggle:checked ~ ul {
max-height: 1000px;
transition: max-height 1s ease;
}
nav #nav-toggle:checked ~ label:after {
content: 'Close';
background-color: #fff;
color: #337AB7;
}
nav li {
margin: .5em 0;
}
nav a {
display: block;
padding: .5em;
text-decoration: none;
color: #fff;
}
nav a:hover,
nav a:active,
nav a:focus {
background-color: #fff;
color: #337AB7;
}
HTML:
<nav>
<h1><a href="#">Title</a></h1>
<input type="checkbox" id="nav-toggle">
<label for="nav-toggle"></label>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
开始的过渡工作正常,但在关闭菜单时,在过渡实际发生之前会有某种延迟。如何停止这种延迟?
【问题讨论】:
标签: css delay transition