我有一个列表,我在div中包装并将其向右浮动:
我需要能够让li从右到左展开,如下图所示:
因此对于列表id执行此操作:
<div id="menu-wrapper">
<ul>
<li><a href=""><img src="btn1.gif" alt="" /></a></li>
<li><a href=""><img src="btn2.gif" alt="" /></a></li>
</ul>
</div>
// CSS
#menu-wrapper {float:right;width:40px;}
如何将图片从右到左悬停在图像上?
答案 0 :(得分:2)
使用max-width
来制作动画效果
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background: url('http://placeimg.com/640/480/nature');
background-size: cover;
}
#menu-wrapper {
text-align: right;
}
.nav {
list-style: none;
display: inline-block;
margin: 0 auto;
}
.cell {
float: right;
clear: both;
background: lightgrey;
margin: 5px 0;
padding: 10px 15px;
}
.cell span {
float: left;
max-width: 0px;
overflow: hidden;
transition: 1s linear;
}
.cell:hover span {
max-width: 100px;
}
<div id="menu-wrapper">
<ul class="nav">
<li class="cell">
<img src="https://cdn3.iconfinder.com/data/icons/streamline-icon-set-free-pack/48/Streamline-18-32.png" /><span>expanded</span>
</li>
<li class="cell">
<img src="https://cdn3.iconfinder.com/data/icons/streamline-icon-set-free-pack/48/Streamline-18-32.png" /><span>expanded</span>
</li>
<li class="cell">
<img src="https://cdn3.iconfinder.com/data/icons/streamline-icon-set-free-pack/48/Streamline-18-32.png" /><span>expanded</span>
</li>
</ul>
</div>
答案 1 :(得分:0)
你应该使用过渡,这是一个小提琴:Fiddle
<div class="button"></div>
<div class="list"></div>
<style type="text/css">
.button {position:relative; width: 40px; height: 40px; float: right; background-color: red; transition: margin-right 1s; z-index: 1000;}
.list {position:relative; width: 100px; height: 40px; float: right; margin-right: -100px; background-color: yellow; transition: margin-right 1s; z-index: 100;}
.button:hover + .list {margin-right: 0px;}
</style>