我做了一个简单的下拉菜单。当我将鼠标悬停在“社交媒体”部分时,我想显示一些社交图标,如下拉菜单。我隐藏了那些社交媒体图标部分。我想让它只在悬停在“社交媒体”部分时可见。但它不起作用。悬停后图标部分不显示。请帮帮我。我找不到我的问题。
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Menu</title>
<link rel="stylesheet" href="./menu.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.2/css/all.min.css">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Lato&display=swap" rel="stylesheet">
</head>
<body>
<div class="main-menu">
<ul>
<li><a href="#">Home</a>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Home</a></li>
<li><a href="#">Home</a></li>
<li><a href="#">Home</a></li>
<li><a href="#">Home</a></li>
</ul>
</li>
<li><a href="#">About</a></li>
<li><a href="#">Service</a></li>
<li><a href="#">Contact</a></li>
<li><a href="#">Register</a></li>
</ul>
</div>
<div class="social">
<ul>
<li><a href="#">Social Media</a>
<ul>
<li><a href="#"><i class="fab fa-facebook-f"></i></a></li>
<li><a href="#"><i class="fab fa-instagram"></i></a></li>
<li><a href="#"><i class="fab fa-twitter"></i></a></li>
<li><a href="#"><i class="fab fa-youtube"></i></a></li>
</ul>
</li>
</ul>
</div>
</body>
</html>
CSS
*{
margin: 0;
padding: 0;
}
.main-menu{
background: black;
}
.main-menu ul {
text-align: center;
}
.main-menu ul li {
display: inline-block;
position: relative;
}
.main-menu ul li a {
color: white;
text-decoration: none;
padding: 15px 56px;
margin-left: -5px;
border-left:1px rgb(70, 67, 67) solid;
display: inline-block;
font-family: 'Lato', sans-serif;
}
.main-menu ul li :last-child{
border-right:1px rgb(70, 67, 67) solid;
}
.main-menu ul li:hover>a{
background-color: rgb(70, 67, 67);
transition: .5s;
}
/* dropdown menu*/
.main-menu ul li ul{
position: absolute;
left: -4px;
top:100%;
width: 300px;
background: black;
visibility: hidden;
opacity: 0;
transform: scaley(0);
transform-origin: top;
}
.main-menu ul li ul li{
display: block;
padding-left: 5px;
}
.main-menu ul li ul li a{
display: block;
border:none;
border-bottom: 1px solid rgb(70, 67, 67);
}
.main-menu ul li ul li:last-child{
border-right: none;
}
/* hover style */
.main-menu ul li:hover ul{
visibility: visible;
opacity: 1;
transition: .5s;
transform: scaley(1);
}
/* social media */
.social{
text-align: center;
margin-top: 50px;
}
.social ul{
list-style: none;
display: inline-block;
}
.social ul li{
height: 42px;
width:225px;
background-color: black;
border-radius: 35px;
position: relative;
}
.social ul li a{
text-decoration: none;
color: white;
font-family: 'Lato', sans-serif;
font-size: 35px;
}
.social ul li:hover{
background-color: rgb(114, 114, 114);
transition: .5s;
}
/* dropdown */
.social ul li ul{
position: absolute;
top: 140%;
left: -145px;
width: 500px;
visibility: hidden;
opacity: 0;
}
.social ul li ul li{
display: inline-block;
height: 80px;
width: 80px;
line-height: 80px;
border-radius: 50%;
margin-left: 22px;
}
.social ul li ul li a{
font-size: 45px;
color: white;
padding:0px;
}
/* hover */
.social ul li :hover .social ul li ul{
visibility: visible;
opacity: 1;
}
答案 0 :(得分:1)
给你。您使用悬停部分作为 .social ul li:hover .social ul li ul
而它应该像 .social:hover ul li ul
* {
margin: 0;
padding: 0;
}
.main-menu {
background: black;
}
.main-menu ul {
text-align: center;
}
.main-menu ul li {
display: inline-block;
position: relative;
}
.main-menu ul li a {
color: white;
text-decoration: none;
padding: 15px 56px;
margin-left: -5px;
border-left: 1px rgb(70, 67, 67) solid;
display: inline-block;
font-family: 'Lato', sans-serif;
}
.main-menu ul li :last-child {
border-right: 1px rgb(70, 67, 67) solid;
}
.main-menu ul li:hover>a {
background-color: rgb(70, 67, 67);
transition: .5s;
}
/* dropdown menu*/
.main-menu ul li ul {
position: absolute;
left: -4px;
top: 100%;
width: 300px;
background: black;
visibility: hidden;
opacity: 0;
transform: scaley(0);
transform-origin: top;
}
.main-menu ul li ul li {
display: block;
padding-left: 5px;
}
.main-menu ul li ul li a {
display: block;
border: none;
border-bottom: 1px solid rgb(70, 67, 67);
}
.main-menu ul li ul li:last-child {
border-right: none;
}
/* hover style */
.main-menu ul li:hover ul {
visibility: visible;
opacity: 1;
transition: .5s;
transform: scaley(1);
}
/* social media */
.social {
text-align: center;
margin-top: 50px;
}
.social ul {
list-style: none;
display: inline-block;
}
.social ul li {
height: 42px;
width: 225px;
background-color: black;
border-radius: 35px;
position: relative;
}
.social ul li a {
text-decoration: none;
color: white;
font-family: 'Lato', sans-serif;
font-size: 35px;
}
.social ul li:hover {
background-color: rgb(114, 114, 114);
transition: .5s;
}
/* dropdown */
.social ul li ul {
position: absolute;
top: 140%;
left: -145px;
width: 500px;
visibility: hidden;
opacity: 0;
}
.social ul li ul li {
display: inline-block;
height: 80px;
width: 80px;
line-height: 80px;
border-radius: 50%;
margin-left: 22px;
}
.social ul li ul li a {
font-size: 45px;
color: white;
padding: 0px;
}
/* hover */
.social:hover ul li ul {
visibility: visible;
opacity: 1;
}
<div class="main-menu">
<ul>
<li><a href="#">Home</a>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Home</a></li>
<li><a href="#">Home</a></li>
<li><a href="#">Home</a></li>
<li><a href="#">Home</a></li>
</ul>
</li>
<li><a href="#">About</a></li>
<li><a href="#">Service</a></li>
<li><a href="#">Contact</a></li>
<li><a href="#">Register</a></li>
</ul>
</div>
<div class="social">
<ul>
<li><a href="#">Social Media</a>
<ul>
<li><a href="#"><i class="fab fa-facebook-f"></i></a></li>
<li><a href="#"><i class="fab fa-instagram"></i></a></li>
<li><a href="#"><i class="fab fa-twitter"></i></a></li>
<li><a href="#"><i class="fab fa-youtube"></i></a></li>
</ul>
</li>
</ul>
</div>
答案 1 :(得分:0)
用这个改变你最后的 css 选择器
await Cart.findOne({ client: userId
}).populate("products");
尽管您现在会遇到无法点击图标的问题,因为它们有 /* hover */
.social:hover ul li ul{
visibility: visible;
opacity: 1;
}
,如果您尝试将鼠标悬停在它们上方,position: absolute;
上的悬停将被移除