绝对定位的Flex项目不会从Firefox中的正常流中删除 [英] Absolutely positioned flex item not being removed from normal flow in Firefox

查看:147
本文介绍了绝对定位的Flex项目不会从Firefox中的正常流中删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有两个div和内容,第三个div是绝对位置的背景。

We have two divs with content and a third div that is a background with absolute position.

容器是一个flexbox。

Container is a flexbox.

在Chrome和Safari中都可以正常工作,但是Firefox会计算绝对定位的div,并在div之间分配空间,例如连续有3个div。

All works fine in Chrome and Safari, but Firefox calculates absolute positioned div, and distributes space between divs like there are 3 divs in a row.

我制作了jsfiddle示例。有什么办法来修复这个bug吗?
https://jsfiddle.net/s18do03e/2/

I've made jsfiddle example. Is there any way to fix this bug? https://jsfiddle.net/s18do03e/2/

div.container {
  display: flex;
  flex-direction: row;
  width: 100%;
  height: 300px;
  justify-content: space-between;
  width: 100%;
  outline: 1px solid;
}
div.c1 {
  background: #aaeecc;
  width: 100px;
  position: relative;
  z-index: 50;
  top: 20px;
  display: flex;
}
div.c2 {
  background: #cceeaa;
  width: 200px;
  position: relative;
  z-index: 50;
  top: 20px;
  display: flex;
}
div.bg {
  background: #ccc;
  width: 100%;
  height: 100%;
  z-index: 0;
  left: 0px;
  top: 0px;
  position: absolute;
  display: flex;
}

<div class="container">
  <div class="c1">Content 1</div>
  <div class="c2">Content 2</div>
  <div class="bg">Background</div>
</div>

推荐答案

正在发生的原因是 justify-content:space-between; 开始,最后在结束。所以只是putt < div class =bg>背景< / div> 介于< div class =c1> ; / div> < div class =c2>内容2< / div>
like this

It is happening because justify-content: space-between; Distribute items evenly The first item at the start, the last at the end. So just putt <div class="bg">Background</div> between <div class="c1">Content 1</div> and <div class="c2">Content 2</div> like this

<div class="container">
    <div class="c1">Content 1</div>
    <div class="bg">Background</div>
    <div class="c2">Content 2</div>

</div>

您可以在 https://developer.mozilla.org/en-US/docs/Web/CSS/justify-content

这篇关于绝对定位的Flex项目不会从Firefox中的正常流中删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆