在Safari中使用Flexbox绝对定位

安德鲁·希尔

Safari表示,Safari完全支持FlexBox。

我只是试图使用flexbox在彼此之间堆叠一些大小不同的div。我真的很好奇为什么它可以在Chrome / Firefox中运行而不能在Safari中运行:

<div class="container">
  <div class="inner-one"></div>
  <div class="inner-two"></div>
</div>
.container {
  width: 15rem;
  height: 15rem;
  border-radius: 50%;
  background-color: blue;

  display: flex;
  align-items: center;
  justify-content: center;
}

.container div {
  position: absolute;
}

.inner-one {
  width: 13rem;
  height: 13rem;
  border-radius: 50%;
  background-color: green;
}

.inner-two {
  width: 11rem;
  height: 11rem;
  border-radius: 50%;
  background-color: purple;
}

在这里查看JSFiddle:https ://jsfiddle.net/19n95exf/3/

一个儿子

因为position: absolute;break display: flextransform: translate改用

    .container {
      position: relative;
      width: 15rem;
      height: 15rem;
      border-radius: 50%;
      background-color: blue;
    }

    .container div {
      border-radius: 50%;
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%,-50%);
    }

    .inner-one {
      width: 13rem;
      height: 13rem;
      background-color: green;
    }

    .inner-two {
      width: 11rem;
      height: 11rem;
      background-color: purple;
    }
    <div class="container">
      <div class="inner-one"></div>
      <div class="inner-two"></div>
    </div>


或者给内部元素一个左/上值

    .container {
      width: 15rem;
      height: 15rem;
      border-radius: 50%;
      background-color: blue;

      display: flex;
      align-items: center;
      justify-content: center;
    }

    .container div {
      border-radius: 50%;
      position: absolute;
    }

    .inner-one {
      left: 1.5rem;
      top: 1.5rem;
      width: 13rem;
      height: 13rem;
      background-color: green;
    }

    .inner-two {
      left: 2.5rem;
      top: 2.5rem;
      width: 11rem;
      height: 11rem;
      background-color: purple;
    }
<div class="container">
      <div class="inner-one"></div>
      <div class="inner-two"></div>
</div>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Flexbox无法在Safari中使用

Flexbox和绝对定位在Chrome和Safari中不起作用

Flexbox,绝对定位,高度为100%

Safari上动画的绝对定位失败

Safari 中绝对定位输入的位置关闭

使用flexbox父级在绝对定位的div中垂直居中,右对齐,多行文本

使用绝对定位破坏文本

绝对定位元素不在Safari iOS中的其他绝对定位元素之上

由于滚动菜单消失,使用flexbox的固定元素在iPhone移动Safari上重新定位

将绝对定位的元素与flexbox垂直对齐

获取绝对定位的链接以与flexbox一致显示

使用CSS定位div:使用绝对定位div的布局问题

不使用绝对定位的HTML布局

如何使用CSS下推绝对定位的div

如何不使用绝对定位CSS

使用Bootstrap绝对定位中心图像位置

在定位元素时使用边距还是绝对定位?

如何移动包含使用绝对定位定位的图像的整个 <div>?

相对定位与绝对定位

定位Safari时,如何在TypeScript(angular2)中使用await / async?

在可重定位程序中使用PC相对寻址进行绝对寻址。修改记录将是什么样的?

在改造中使用绝对URL

在JScrollPane中使用绝对布局

在Safari中使用getElementByClassName

使用 flexbox 居中文本定位

为什么`height:100%`和绝对定位在flexbox中不起作用?

与绝对定位 div 重叠的 flexbox 项目的图像和文本(工具提示)

具有表格和绝对定位功能的Flexbox在IE 10、11或Edge中不起作用

如何在Safari中将flex容器的绝对定位的子项居中居中?