我正在做一个足球网站。我打算用下面的代码设置一个下拉菜单:
<li>
<a href="#">Team Profile</a>
<ul>
<li><a href="#">Chelsea</a></li>
<li><a href="#">Man City</a></li>
<li><a href="#">Southampton</a></li>
<li><a href="#">Man Utd</a></li>
<li><a href="#">Arsenal</a></li>
<li><a href="#">Liverpool</a></li>
<li><a href="#">West Ham</a></li>
<li><a href="#">Newcastle</a></li>
<li><a href="#">Leichester</a></li>
<li><a href="#">QPR</a></li>
<li><a href="#">Burnley</a></li>
<li><a href="#">Aston Villa</a></li>
<li><a href="#">Stoke City</a></li>
<li><a href="#">Crystal Palace</a></li>
<li><a href="#">Hull City</a></li>
<li><a href="#">Sunderland</a></li>
<li><a href="#">Tottenham Hotspur</a></li>
<li><a href="#">Everton</a></li>
<li><a href="#">Swansea</a></li>
<li><a href="#">West Brom</a></li>
</ul>
</li>
我用下面的css代码设置了下翻动画:
.myDropDown
{
height: 50px;
overflow: auto;
}
.nav ul {
*zoom:1;
list-style:none;
margin:0;
padding:0;
background:#333;
}
.nav ul:before,.nav ul:after {
content:"";
display:table;
}
.nav ul:after {
clear:both;
}
.nav ul > li {
float:left;
position:relative;
}
.nav a {
display:block;
padding:10px 20px;
line-height:1.2em;
color:#fff;
border-left:1px solid #595959;
}
.nav a:hover {
text-decoration:none;
background:#595959;
}
.nav li ul {
background:#273754;
}
.nav li ul li {
width:200px;
}
.nav li ul a {
border:none;
}
.nav li ul a:hover {
background:rgba(0,0,0,0.2);
}
.nav li ul {
position:absolute;
left:0;
top:36px;
z-index:1;
max-height:0;
overflow:hidden;
-webkit-transform:perspective(400) rotate3d(1,0,0,-90deg);
-webkit-transform-origin:50% 0;
-webkit-transition:350ms;
-moz-transition:350ms;
-o-transition:350ms;
transition:350ms;
}
.nav ul > li:hover ul {
max-height:1000px;
-webkit-transform:perspective(400) rotate3d(0,0,0,0);
}
* { margin: 0; padding: 0; }
body { font: 15px Helvetica, Sans-Serif; }
html { overflow-y: scroll; }
#page-wrap { width: 720px; margin: 25px auto; }
p { margin: 0 0 8px 0; }
a { text-decoration: none; }
img { vertical-align: middle; }
a img { border: 0; 180}
ul { list-style: none; }
h1 { margin: 0 0 10px 0; }
/*
LEVEL ONE
*/
ul.dropdown { position: relative; width: 100%; }
ul.dropdown li { font-weight: bold; float: left; width: 180px; background: #ccc; position: relative; }
ul.dropdown a:hover { color: #000; }
ul.dropdown li a { display: block; padding: 20px 8px; color: #222; position: relative; z-index: 2000; }
ul.dropdown li a:hover,
ul.dropdown li a.hover { background: #F3D673; position: relative; }
/*
LEVEL TWO
*/
ul.dropdown ul { display: none; position: absolute; top: 0; left: 0; width: 180px; z-index: 1000; }
ul.dropdown ul li { font-weight: normal; background: #f6f6f6; color: #000; border-bottom: 1px solid #ccc; }
ul.dropdown ul li a { display: block; background: #eee !important; }
ul.dropdown ul li a:hover { display: block; background: #F3D673 !important; }
.FixedHeightContainer
{
float:right;
height: 250px;
width:250px;
overflow: auto;
}
.Content
{
}
但我的下拉时间太长。所以,我决定制作一个可滚动的。所以,我添加了这段代码。
.scrollable-menu {
height: auto;
max-height: 200px;
overflow-x: hidden;
}
但是,我的菜单不可滚动,除非我使用这个代码并且这个翻转动画已经消失了。
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">Scrollable Menu <span class="caret"></span></button>
<ul class="dropdown-menu scrollable-menu" role="menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
</ul>
</div>
答案 0 :(得分:0)
您必须添加overflow-y:auto或滚动以使其在垂直方向上滚动。你刚刚禁用了水平滚动。所以适当的CSS将是
.scrollable-menu {
height: auto;
max-height: 200px;
overflow-x: hidden;
overflow-y: auto;
}
希望有所帮助。玩得开心。
答案 1 :(得分:0)
您可以尝试在.dropdown-menu
-webkit-transform-origin: top;
transform-origin: top;
animation-fill-mode: forwards;
-webkit-transform: scale(1, 0);
display: block;
transition: all 0.2s linear;
-webkit-transition: all 0.2s linear;
这一切都在.open>.dropdown-menu
display: block;
-webkit-transform: scale(1, 1);
transform: scale(1, 1);
opacity: 1;