gpt4 book ai didi

html - 下拉菜单和动画

转载 作者:行者123 更新时间:2023-11-28 12:51:43 25 4
gpt4 key购买 nike

我是 HTML5 和 CSS3 的新手。我正在尝试使用线性动画的下拉菜单。我已经从现有模板复制了动画,剩下的最后一件事就是显示下拉菜单项。我在给定的 CSS3 中有什么错?

HTML 文件:

<!DOCTYPE html>
<html>
<head>

<meta name="viewport" content="initial-scale=1.0, user-scalable=no" charset="utf-8" />

<link rel="stylesheet" type="text/css" href="style.css">
<title>My Page Title</title>
</head>

<body>
<div>

<ul class="menu" id="nav">
<li><a href=""><span>
Tab5</span></a>
<ul class="menu-hover">
<li><a href="">Tab5_1</a></li>
<li><a href="">Tab5_2</a></li>
<li><a href="">Tab5_3</a></li>
</ul>
</li>

<li><a href=""><span>
Tab4
</span></a>
<ul class="menu-hover">
<li><a href="">Tab4_1</a></li>
<li><a href="">Tab4_2</a></li>
</ul>
</li>

<li><a href="candidates.html"><span>Tab3</span></a>
<ul class="menu-hover">
<li><a href="">Tab3_1</a></li>
<li><a href="">Tab3_2</a></li>
<li><a href="">Tab3_3</a></li>
<li><a href="">Tab3_4</a></li>
</ul>
</li>

<li><a href=""><span>
Tab2
</span></a>
<ul class="menu-hover">
<li><a href="">Tab2_1</a></li>
<li><a href=""> Tab2_2</a></li>
<li><a href="">Tab2_3 </a></li>
</ul>
</li>


<li><a href="vision.html"><span>Tab1 </span></a>
<ul class="menu-hover">
<li><a href="">Tab1_1 </a></li>
<li><a href="">Tab1_2</a></li>
<li><a href="">Tab1_3</a></li>
</ul>
</li>
</ul>
</div>

<div><footer id="footer"></footer></div>
</body>
</html>

CSS3 文件:

@charset "utf-8";
/* CSS Document */

* {
margin:0px;
padding:0px;
}
body {
background:#f4f4f4;
}

#nav {
width:933px;
margin:0 auto;
height:250px;
padding-top:20px;
}

ul li {
background:#2a2a2a;
list-style: none;
height: 44px;
float:left;
padding:10px 5px;
}
ul li a {
width: 175px;
height: 40px;
line-height: 53px;
border-bottom: 4px solid #636393;
padding:0px;
color: #fff;
font-size:18px;
font-weight:lighter;
text-align:center;
text-decoration: none;
display: block;
-webkit-transition: .2s all linear;
-moz-transition: .2s all linear;
-o-transition: .2s all linear;
transition: .2s all linear;
}

ul li a:visited {
color:#fff;
}


ul li:nth-child(1) a , #myID li:nth-child(1) a, #myID li:nth-child(2) a , #myID li:nth-child(3) a
{
border-color: #636393;
}

ul li:nth-child(2) a {
border-color: #B5222D;
}
ul li:nth-child(3) a {
border-color: #D4953C;
}
ul li:nth-child(4) a {
border-color: #609491;
}
ul li:nth-child(5) a {
border-color: #87A248;
}

ul li:nth-child(1) a:hover {
border-bottom: 35px solid #636393;
height: 9px;
color: #fff;
}

ul li:nth-child(2) a:hover {
border-bottom: 35px solid #B5222D;
height: 9px;
color: #fff;
}
ul li:nth-child(3) a:hover {
border-bottom: 35px solid #D4953C;
height: 9px;
color: #fff;
}

ul li:nth-child(4) a:hover {
border-bottom: 35px solid #609491;
height: 9px;
color: #fff;
}

ul li:nth-child(5) a:hover {
border-bottom: 35px solid #87A248;
height: 9px;
color: #fff;
}

ul.menu-hover{
visibility: hidden;
position: absolute;
top:100%;
opacity: 0;
height: 0;
width: 150px;
border-bottom: 1px solid #636393;
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}

.menu li:hover .menu-hover{
visibility: visible;
height: 40px;
opacity: 1;
}

ul.menu-hover li{
height: 100%;
border-bottom: 4px solid #000;
background-color: #2a2a2a;
border-left: none;
border-right: none;

}

ul.menu-hover li:hover{
background-image: -webkit-linear-gradient(#2a2a2a, #434343);
background-image: -moz-linear-gradient(#2a2a2a, #434343);
background-image: -o-linear-gradient(#2a2a2a, #434343);
background-image: linear-gradient(#2a2a2a, #434343);
box-shadow: none;
}

最佳答案

尝试

.menu ul ul { position: absolute; }

看起来你只在悬停时才看到它。您无需将其悬停。

对不起

也先试试这个

ul .menu-hover { position: absolute; }

在你的代码中你有 ul.menu-hover,它们之间需要有一个空格

关于html - 下拉菜单和动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16885539/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com