所以,我在网上使用了侧边栏菜单。首先,这个侧边栏只有100px,当我将鼠标悬停在它上面时,它会显示所有侧边栏。这是悬停之前和之后的图像:
我的HTML代码:
.sidenav {
height: 100%;
width: 100px;
position: fixed;
z-index: 2;
top: 0;
left: 0;
background-color: #111;
overflow-x: hidden;
padding-top: 60px;
transition: 0.8s;
}
.sidenav:hover{
width: 250px;
transition: 0.8s;
}
.sidenav a {
float:left;
width:100%;
padding: 8px 8px 8px 32px;
text-decoration: none;
font-size: 20px;
color: #818181;
display: block;
opacity: 0;
transition: opacity 1300ms
}
.sidenav:hover a {
opacity: 1
}
.icon{
display: block;
position: relative;
left: 50%;
top: 50%;
width: 15px;
height: 15px;
float: left;
border-radius: 50%;
border: 1px solid red;
border-top-color: transparent;
-webkit-animation: spin 2s linear infinite;
animation: spin 2s linear infinite;
}

<body>
<div id="mySidenav" class="sidenav"> <!-- CSSnya di 2691 -->
<br><br>
<a href="#">Home</a>
<a href="#">Menu 1</a>
<a href="#">Menu 2</a>
<a href="#">Menu 3</a>
<a href="#">Menu 4</a>
<a href="#">Menu 5</a>
</div>
</body>
&#13;
当侧边栏没有悬停时,我的所有链接菜单都会隐藏,并会在悬停时显示。我的问题是如何只在侧边栏没有悬停时显示图标,并在悬停时显示所有图标,我使用此类: 所以它仍然显示侧边栏没有悬停,仍然在链接菜单的一行?感谢
答案 0 :(得分:2)
您可以使用FontAwesome作为图标。希望它有所帮助。
.sidenav a {
float: left;
width: 250px;
padding: 8px 8px 8px 32px;
text-decoration: none;
font-size: 16px;
display: block;
line-height: 37px;
color: transparent;
transition: 1300ms;
height: 30px;
font-family: arial;
letter-spacing: 1px;
text-transform: uppercase;
}
i {
display: block;
position: relative;
width: 15px;
height: 15px;
float: left;
border-radius: 50px;
border: 1px solid red;
padding: 10px;
text-align: center;
line-height: 15px !important;
color: #fff;
opacity: 1;
margin-right: 10px;
font-size: 15px !important;
}
.sidenav {
width: 100px;
left: 0;
background-color: #111;
overflow-x: hidden;
padding-top: 60px;
transition: 0.8s;
}
.sidenav:hover {
width: 250px;
overflow: hidden;
transition: 0.8s;
}
.sidenav:hover a {
color: #fff;
}
<script src="https://use.fontawesome.com/7a90a673fc.js"></script>
<div id="mySidenav" class="sidenav">
<br><br>
<a href="#"><i class="fa fa-bars"></i> Home</a>
<a href="#"><i class="fa fa-comment"></i> Menu 1</a>
<a href="#"><i class="fa fa-users"></i> Menu 2</a>
<a href="#"><i class="fa fa-thumbs-up"></i> Menu 3</a>
<a href="#"><i class="fa fa-facebook"></i> Menu 4</a>
<a href="#"><i class="fa fa-close"></i> Menu 5</a>
</div>
答案 1 :(得分:0)
.sidenav {
height: 100%;
width: 250px;
position: fixed;
z-index: 2;
top: 0;
left: 0;
background-color: #111;
overflow: hidden;
padding-top: 60px;
transition: 0.8s;
transform: translatex(-150px);
}
.sidenav:hover {
transition: 0.8s;
transform: translatex(0);
}
.sidenav a {
display: block;
width: 150px;
padding: 8px 8px 8px 32px;
text-decoration: none;
font-size: 20px;
color: #818181;
transition: opacity 1300ms;
position: relative;
}
.sidenav a::after {
content: '';
display: block;
position: absolute;
right: -16px;
top: calc(50% - 8px);
width: 15px;
height: 15px;
border-radius: 50%;
border: 1px solid red;
border-top-color: transparent;
-webkit-animation: spin 2s linear infinite;
animation: spin 2s linear infinite;
}
&#13;
<div id="mySidenav" class="sidenav">
<!-- CSSnya di 2691 -->
<br>
<br>
<a href="#">Home</a>
<a href="#">Menu 1</a>
<a href="#">Menu 2</a>
<a href="#">Menu 3</a>
<a href="#">Menu 4</a>
<a href="#">Menu 5</a>
</div>
&#13;