如果我从float:left中删除.action-button属性,转换动画就无法工作。你能解释一下这里发生了什么吗?
标记:
<a href="#" class="action-button animate green">Are</a>风格:
.action-button
{
position: relative;
padding: 10px 40px;
margin: 0px 10px 10px 0px;
float: left;
border-radius: 8px;
font-family: 'Pacifico', cursive;
font-size: 25px;
color: #FFF;
text-decoration: none;
}
.green
{
background-color: #82BF56;
border-bottom: 5px solid #669644;
text-shadow: 0px -2px #669644;
}
.action-button:active
{
transform: translate(0px,5px);
-webkit-transform: translate(0px,5px);
border-bottom: 1px solid;
}第17行:http://codepen.io/koriolis/pen/euAEg
发布于 2015-07-09 08:55:46
这是因为a元素是inline元素,因为它们对齐父元素,并且不清除任何一方。
添加float: left时,它会将元素从inline更改为block,但也会删除clear: both,并允许元素彼此对齐。
如果不希望标记在页面上浮动,则可以使用float实现与inline-block相同的效果。
.action-button {
position: relative;
padding: 10px 40px;
margin: 0px 10px 10px 0px;
display: inline-block;
border-radius: 8px;
font-family: 'Pacifico', cursive;
font-size: 25px;
color: #FFF;
text-decoration: none;
}CodePen实例
发布于 2015-07-09 08:54:36
a -默认display: inlinefloat: left - display属性设置为阻止float: left - a时,display: inlinedisplay: inline-block而不是float: left
body {
padding: 50px;
}
.animate {
transition: all 0.1s;
-webkit-transition: all 0.1s;
}
.action-button {
position: relative;
padding: 10px 40px;
margin: 0px 10px 10px 0px;
display: inline-block;
border-radius: 8px;
font-family:'Pacifico', cursive;
font-size: 25px;
color: #FFF;
text-decoration: none;
}
.blue {
background-color: #3498DB;
border-bottom: 5px solid #2980B9;
text-shadow: 0px -2px #2980B9;
}
.red {
background-color: #E74C3C;
border-bottom: 5px solid #BD3E31;
text-shadow: 0px -2px #BD3E31;
}
.green {
background-color: #82BF56;
border-bottom: 5px solid #669644;
text-shadow: 0px -2px #669644;
}
.yellow {
background-color: #F2CF66;
border-bottom: 5px solid #D1B358;
text-shadow: 0px -2px #D1B358;
}
.action-button:active {
transform: translate(0px, 5px);
-webkit-transform: translate(0px, 5px);
border-bottom: 1px solid;
}<a href="#" class="action-button animate blue">Hello</a>
<a href="#" class="action-button animate red">How</a>
<a href="#" class="action-button animate green">Are</a>
<a href="#" class="action-button animate yellow">You?</a>
小提琴
https://stackoverflow.com/questions/31312447
复制相似问题