gpt4 book ai didi

html - 如何在一行中制作图标和 `a`

转载 作者:太空宇宙 更新时间:2023-11-04 01:58:33 25 4
gpt4 key购买 nike

因此,我在我的网站中使用了侧边栏菜单。一开始,这个侧边栏只有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>

当侧边栏没有悬停时,我所有的链接菜单都是隐藏的,悬停时会出现。我的问题是如何在侧边栏未悬停时仅显示图标,并在其悬停时显示所有图标,我在其中使用此类:所以当侧边栏没有悬停并且仍然与链接菜单在一行时它仍然显示?谢谢

最佳答案

您可以为图标使用 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>

关于html - 如何在一行中制作图标和 `a`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42185756/

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