我正在用html5和css3做一个按钮。我正试图为我的按钮制作一个像这这样的悬停动画。
当鼠标悬停在按钮上时,白色圆圈从中心展开,圆圈内的按钮文字以黑色字体颜色显示(以使其更易读)。我试图在按钮中放一个div,但是我无法将黑色文本放在与按钮文本相同的位置。
发布于 2014-02-23 02:25:41
这确实可以不使用javascript,没有动画,只需要转换。
我能够使用内部元素和内部元素上的伪元素来完成这个任务。有趣的概念,但不是很容易改变,许多硬编码的值基于元素的高度。使用像SCSS这样的预处理程序可以使它更容易操作。
总之,这是代码(可能会被清理一下)
/* HTML */
<div class='outer'>
Contacts
<div class='innerCircle'></div>
</div>
/* CSS */
.outer {
width:150px; height:50px;
border-radius:10px;
background:blue;
text-align:center;
color:white;
line-height:50px;
position:relative;
}
.innerCircle {
position:absolute;
top:50%; left:50%;
background:white;
color:black;
overflow:hidden;
border-radius:50%;
transition:all .5s;
height:0; width:0;
padding-left:-10px;
}
.innerCircle:before {
content:'Contacts';
position:absolute;
margin-left:-2px;
transition:all .5s;
transform:translateX(-25px);
top:-25px;
}
.outer:hover .innerCircle {
margin-left:-25px;
top:0;
height:50px; width:50px;
}
.outer:hover .innerCircle:before {
top:0px;
}https://stackoverflow.com/questions/21514719
复制相似问题