我制作了一个图标补充工具栏,其中包含不同的图标,这些图标在鼠标悬停时会变大。如果我将鼠标悬停在顶部图标上方,则将我悬停在其上方的所有其他图标向下移动。所以我的问题是如何防止图标移动。谢谢。
<div id="icon-bar" class="visible">
<a href="#"><i class="fa fa-home"></i>
<span class="description">Home</span></a>
<a href="#"><i class="fa fa-gamepad"></i>
<span class="description">Games</span></a>
<a href="#"><i class="fa fa-images"></i>
<span class="description">Gallery</span></a>
</div>
<style>
#icon-bar {
width:100px;
height:100%;
background-color:blue;
position:absolute;
bottom:0px;
left:0px;
box-shadow:5px -10px 10px -2px #111;
}
#icon-bar a {
display:block;
text-align:center;
padding:20px;
color:white;
font-size:47px;
transition: all .2s ease-in-out;
}
#icon-bar a:hover {
background-color: #CF0B61;
transform: scale(1.2, 1.2);
}
.description{
display:none;
font-size:12px;
text-align:center;
}
#icon-bar a:hover .description {
display:block;
}
</style>
jsfiddle:https://jsfiddle.net/az0om9dr/
答案 0 :(得分:1)
在图标栏中为标签赋予固定高度
#icon-bar a {
display:block;
text-align:center;
padding:20px;
color:white;
font-size:47px;
transition: all .2s ease-in-out;
}
答案 1 :(得分:1)
用absolute
定位图标,以使其脱离文档流:
#icon-bar {
width:100px;
height:100%;
background-color:blue;
position:absolute;
bottom:0px;
left:0px;
box-shadow:5px -10px 10px -2px #111;
}
#icon-bar a {
position:absolute;
display:block;
text-align:center;
padding:20px;
color:white;
font-size:47px;
transition: all .2s ease-in-out;
}
#icon-bar a:first-child {
top:0;
}
#icon-bar a:nth-child(2) {
top:94px;
}
#icon-bar a:nth-child(3) {
top:188px;
}
#icon-bar a:hover {
background-color: #CF0B61;
transform: scale(1.2, 1.2);
}
.description{
display:none;
font-size:12px;
text-align:center;
}
#icon-bar a:hover .description {
display:block;
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">
<div id="icon-bar" class="visible">
<a href="#"><i class="fa fa-home"></i><span class="description">Home</span></a>
<a href="#"><i class="fa fa-gamepad"></i><span class="description">Games</span></a>
<a href="#"><i class="fa fa-images"></i><span class="description">Gallery</span></a>
</div>