【发布时间】:2015-12-29 23:48:17
【问题描述】:
我在 CSS3 中使用 transform 时遇到了一个奇怪的行为。
这是我的代码:
*, *:before, *:after {
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
}
.btn_exchange a {
position: relative;
text-decoration: none;
display: block;
width: 150px;
float: left;
color: #ffffff;
font-size: 14px;
background: #0ea2d3;
box-shadow: 0 3px 0 0 rgba(7, 154, 190, 0.75);
text-align: center;
font-weight: bold;
}
@keyframes pulse {
0% {
transform: scale(1);
}
50% {
transform: scale(1.05);
}
100% {
transform: scale(1);
}
}
@-webkit-keyframes pulse {
0% {
transform: scale(1);
}
50% {
transform: scale(1.05);
}
100% {
transform: scale(1);
}
}
a.abc {
z-index: 0;
-webkit-animation: pulse 1s linear 0s infinite alternate;
animation: pulse 1s linear infinite;
}
#box_avatar {
position: relative;
margin: 0 auto;
-webkit-border-radius: 62.5px;
-moz-border-radius: 62.5px;
-ms-border-radius: 62.5px;
-o-border-radius: 62.5px;
border-radius: 62.5px;
width: 125px;
height: 125px;
border: 2px solid #ccc;
display: block;
overflow: hidden;
}
#img_avatar {
width: 125px;
height: 125px;
cursor: pointer;
border-radius: 62.5px;
}
#bg_gray {
background: #4c4747;
width: 100%;
position: absolute;
bottom: 0;
padding: 8px 0 10px 0;
opacity: 0.8;
}
#bg_gray img {
display: block;
width: 20px;
margin: 0 auto;
}
<div class="btn_exchange fl bad">
<a class="button abc" href="#">Button</a>
</div>
<div id="box_avatar">
<img id="img_avatar" src="http://i.imgur.com/O29DJOZ.jpg" alt="avatar" />
<div id="bg_gray">
<img src="http://i.imgur.com/m5qIRID.png" alt="btn_camera" />
</div>
</div>
<div class="btn_exchange fl good">
<a class="button abc" href="#">Button</a>
</div>
当我使用.bad div(删除.good div)时会出现问题,然后包含相机图标的灰色背景不在圆形图像内。
如果我在 CSS 中删除动画 transform,按钮将不再跳动,但灰色背景将在圆形图像内。
有谁知道它是什么以及如何解决它?
【问题讨论】:
标签: html css css-animations css-transforms