我的 CSS 悬停代码在侧边导航栏中的确切错误是什么?
What's the exact bug with my CSS hovering code in side nav bar?
**在我的社交媒体图标项目中,我尝试使用不透明度 0 隐藏我的文本。当用户将鼠标悬停在我的标签或图标上时,将显示文本。但我的悬停过渡不起作用。请首先尝试在我的 CSS in .icon.Please 中使用 opacity 1 来解决我的悬停问题。我不明白这是什么错误
:root {
--darkblu: #2c3e50;
--linkclr: #fff;
--lightblue: lightblue;
--violet: violet;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.side_nav {
background-color: var(--darkblu);
height: 100vh;
width: 50px;
position: fixed;
display: flex;
flex-flow: column nowrap;
justify-content: flex-start;
align-items: center;
/* overflow: hidden; */
}
.icon_holder {
display: flex;
justify-content: center;
align-items: center;
position: relative;
}
.icon {
width: 100%;
height: 100%;
/* background-color: var(--lightblue); */
}
.side_nav .icon_holder .icon a {
text-decoration: none;
color: var(--linkclr);
font-size: 80%;
/* width: 100%;
height: 100%; */
display: inline-block;
margin: 20px 0px;
padding: 10px;
}
.icon_holder span {
position: absolute;
left: 100%;
width: 100px;
background-color: var(--violet);
margin: 0px 24px;
padding: 5px;
text-align: center;
border-radius: 4px;
opacity: 0;
}
.icon_holder span::before {
content: '';
position: absolute;
height: 10px;
width: 10px;
transform: rotate(45deg);
background-color: var(--violet);
top: 35%;
left: -5%;
}
.icon_holder:nth-child(1):hover .icon_holder span {
opacity: 1;
}
<!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>Document</title>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.4/css/all.css" integrity="sha384-DyZ88mC6Up2uqS4h/KRgHuoeGwBcD4Ng9SiP4dIRy0EXTlnuz47vAwmeGwVChigm" crossorigin="anonymous">
</head>
<body>
<div class="side_nav">
<div class="icon_holder">
<div class="icon"><a href="#"><i class="fas fa-home"></i></a></div>
<span>Home</span>
</div>
<div class="icon_holder">
<div class="icon"><a href="#"><i class="fas fa-blog"></i></a></div>
<span>Blog</span>
</div>
<div class="icon_holder">
<div class="icon"><a href="#"><i class="fas fa-question"></i></a></div>
<span>About Us</span>
</div>
<div class="icon_holder">
<div class="icon"><a href="#"><i class="fab fa-whatsapp"></i></a></div>
<span>Whatsapp</span>
</div>
<div class="icon_holder">
<div class="icon"><a href="#"><i class="fas fa-user"></i></a></div>
<span>User Access</span>
</div>
</div>
</body>
</html>
使用这个:
.icon_holder span {
position: absolute;
left: 100%;
width: 100px;
background-color: var(--violet);
margin: 0px 24px;
padding: 5px;
text-align: center;
border-radius: 4px;
opacity: 0;
transition: 500ms all;//add transition
}
.icon_holder:hover span{
opacity: 1;
}
**在我的社交媒体图标项目中,我尝试使用不透明度 0 隐藏我的文本。当用户将鼠标悬停在我的标签或图标上时,将显示文本。但我的悬停过渡不起作用。请首先尝试在我的 CSS in .icon.Please 中使用 opacity 1 来解决我的悬停问题。我不明白这是什么错误
:root {
--darkblu: #2c3e50;
--linkclr: #fff;
--lightblue: lightblue;
--violet: violet;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.side_nav {
background-color: var(--darkblu);
height: 100vh;
width: 50px;
position: fixed;
display: flex;
flex-flow: column nowrap;
justify-content: flex-start;
align-items: center;
/* overflow: hidden; */
}
.icon_holder {
display: flex;
justify-content: center;
align-items: center;
position: relative;
}
.icon {
width: 100%;
height: 100%;
/* background-color: var(--lightblue); */
}
.side_nav .icon_holder .icon a {
text-decoration: none;
color: var(--linkclr);
font-size: 80%;
/* width: 100%;
height: 100%; */
display: inline-block;
margin: 20px 0px;
padding: 10px;
}
.icon_holder span {
position: absolute;
left: 100%;
width: 100px;
background-color: var(--violet);
margin: 0px 24px;
padding: 5px;
text-align: center;
border-radius: 4px;
opacity: 0;
}
.icon_holder span::before {
content: '';
position: absolute;
height: 10px;
width: 10px;
transform: rotate(45deg);
background-color: var(--violet);
top: 35%;
left: -5%;
}
.icon_holder:nth-child(1):hover .icon_holder span {
opacity: 1;
}
<!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>Document</title>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.4/css/all.css" integrity="sha384-DyZ88mC6Up2uqS4h/KRgHuoeGwBcD4Ng9SiP4dIRy0EXTlnuz47vAwmeGwVChigm" crossorigin="anonymous">
</head>
<body>
<div class="side_nav">
<div class="icon_holder">
<div class="icon"><a href="#"><i class="fas fa-home"></i></a></div>
<span>Home</span>
</div>
<div class="icon_holder">
<div class="icon"><a href="#"><i class="fas fa-blog"></i></a></div>
<span>Blog</span>
</div>
<div class="icon_holder">
<div class="icon"><a href="#"><i class="fas fa-question"></i></a></div>
<span>About Us</span>
</div>
<div class="icon_holder">
<div class="icon"><a href="#"><i class="fab fa-whatsapp"></i></a></div>
<span>Whatsapp</span>
</div>
<div class="icon_holder">
<div class="icon"><a href="#"><i class="fas fa-user"></i></a></div>
<span>User Access</span>
</div>
</div>
</body>
</html>
使用这个:
.icon_holder span {
position: absolute;
left: 100%;
width: 100px;
background-color: var(--violet);
margin: 0px 24px;
padding: 5px;
text-align: center;
border-radius: 4px;
opacity: 0;
transition: 500ms all;//add transition
}
.icon_holder:hover span{
opacity: 1;
}