我想創建一個帶滑動子菜單項的菜單欄。爲此,我編寫了下面的代碼,但轉換(下滑)效果在懸停時無效。我只想用css來做。有人請幫助我。使用css轉換懸停時滑動菜單的問題
<html>
<head>
<style type="text/css">
.menu {
width: 100%;
background-color: rgba(250,250,250,0.9);
box-shadow: 0 2px 2px -2px rgba(0,0,0,0.6);
}
.menu ul{
list-style: none;
color: #31373d;
padding: 0;
margin: 0px 20px;
position: relative;
}
.menu ul li{
height: 35px;
line-height: 35px;
font-weight: 600;
width: 100px;
text-align: center;
.menu > ul {
z-index: 0;
}
.menu > ul > li {
display: inline-block;
padding: 5px 10px;
margin: 0;
margin-right: 5px;
position: relative;
cursor: pointer;
text-shadow: 1px 2px 2px white;
}
.menu ul ul {
display: none;
height: 0px; /* Height initially set to 0 */
overflow: hidden;
background: #f0f0f0;
-moz-transition: height 0.5s linear;
text-shadow: 1px 2px 2px #f0f0f0;
box-shadow: 0 4px 2px -2px rgba(0,0,0,0.1);
z-index: 2;
border: 1px solid #a0a0a0;
-webkit-transition: height 0.3s linear;
-moz-transition: height 0.3s linear;
-o-transition: height 0.3s linear;
-ms-transition: height 0.3s linear;
transition: height 0.3s linear;
left: -23px;
top: 45px;
}
.menu > ul > li:hover ul {
display: block;
height: auto; /* Height set to auto for the transition to take effect */
position: absolute;
}
.menu ul ul li{
width: 200px;
height: 40px;
line-height: 40px;
border-bottom: 1px solid #a0a0a0;
}
</style>
</head>
<body>
<div class="menu">
<ul>
<li class="newbox">Home
<ul>
<li>City Home</li>
<li>Country Home</li>
</ul>
</li>
<li class="newbox">About
<ul>
<li>About Me</li>
<li>About others</li>
<li>About my family</li>
</ul>
</li>
<li class="newbox">Contact
<ul>
<li>Contact Me</li>
</ul>
</li>
</ul>
</div>
</body>
</html>
感謝
它仍然無法正常工作。請幫忙! – Bharat