【问题标题】:flexbox not aligning :after & :before correctly in firefox and safariflexbox 未对齐 :after & :before 在 firefox 和 safari 中正确
【发布时间】: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看到这个。

【问题讨论】:

    标签: css firefox flexbox


    【解决方案1】:

    试一试...

    #pulse::before, #pulse::after {
        content: '';
        position: absolute;
        display: block;
        width: 12.5px;
        height: 33.3px;
        background: #efefef;
        animation: pulse 750ms infinite;
        top: 50%;
        transform: translateY(-50%);
    }
    

    https://jsfiddle.net/opt4jmmt/

    【讨论】:

      猜你喜欢
      • 2014-02-08
      • 2013-09-25
      • 1970-01-01
      • 2018-05-28
      • 2018-08-29
      • 2018-10-31
      • 1970-01-01
      • 2015-11-28
      • 2018-12-17
      相关资源
      最近更新 更多