【发布时间】:2023-03-06 22:50:01
【问题描述】:
我正在制作加载动画。我的问题是,将这些与 flexbox 居中似乎只能在 Chrome 中正常工作。 :before & :after 在 Firefox 中位于其父 div 的底部,在 safari 中位于顶部。
#pulse-box {
width: 100%;
height: 100px;
display: flex;
justify-content: center;
align-items: center;
}
#pulse {
position: relative;
width: 12.5px;
height: 50px;
animation: pulse 750ms infinite;
animation-delay: 250ms;
display: flex;
justify-content: center;
align-items: center;
}
#pulse:before,
#pulse:after {
content: '';
position: absolute;
display: block;
width: 12.5px;
height: 33.3px;
background: #efefef;
animation: pulse 750ms infinite;
}
#pulse:before {
left: -25px;
/* -(pulse height / 1.5) */
}
#pulse:after {
left: 25px;
/* (pulse height / 1.5) */
animation-delay: 500ms;
}
@keyframes pulse {
0%,
10% {
background: #efefef;
}
50% {
background: #5b5b5b;
}
}
<div id="pulse-box">
<div id="pulse" />
</div>
你也可以在我做的jsfiddle看到这个。
【问题讨论】: