作者:瑶2012瑶_881 | 来源:互联网 | 2023-05-18 20:04
This question already has an answer here:
这个问题在这里已有答案:
- Flexbox code working on all browsers except Safari. Why? 2 answers
- Flexbox代码适用于除Safari之外的所有浏览器。为什么? 2个答案
I've made a flex layout in which four columns/boxes sit side-by-side within a parent div. I've added a media query at 980px that increases the width of the columns and adds a flex-wrap to push the two right hand columns onto a new row, creating a 2 x 2 style layout. This works in every browser except Safari, in which the results are very unpredictable.
我做了一个flex布局,其中四个列/盒在父div中并排放置。我在980px处添加了一个媒体查询,增加了列的宽度,并添加了一个flex-wrap,将两个右侧列推到一个新行上,创建一个2 x 2样式的布局。这适用于除Safari之外的所有浏览器,其结果非常难以预测。
Fiddle: https://jsfiddle.net/gjy1t16p/6/
小提琴:https://jsfiddle.net/gjy1t16p/6/
If you view this in Chrome and drag the window below 980px, it will work in the way I've described above. In Safari however, although I've not managed to recreate the problem exactly, the boxes stack vertically instead.
如果您在Chrome中查看此内容并将窗口拖动到980px以下,它将按照我上面描述的方式工作。然而,在Safari中,虽然我没有设法完全重新创建问题,但是盒子垂直堆叠。
As I mentioned, the results are unpredictable – when implemented on my website, the layout is actually closer to working than in the Fiddle I've made. On the website, the 2 x 2 layout works, but only if the fourth box has no text / widgets inside it. Once it contains content that reaches the full width of the box, it moves down to the left and sits underneath the third box, as happened to any other boxes I tried adding after it.
正如我所提到的,结果是不可预测的 - 当在我的网站上实现时,布局实际上比我制作的小提琴更接近工作。在网站上,2 x 2布局有效,但前提是第四个框内没有文本/小部件。一旦它包含到达框的整个宽度的内容,它向下移动到第三个框的下面,就像我尝试在其后添加的任何其他框一样。
If anyone has experienced this bug before and knows how to solve it, I'd be really grateful. I've spent all day trying to fix it and I'm completely out of ideas.
如果有人之前遇到过这个bug并且知道如何解决它,我会非常感激。我整天都在努力解决这个问题,而且我完全没有想法。
HTML:
HTML:
CSS:
CSS:
.footer {
height: auto;
width: 100%;
background-color: #efefef;
display:-webkit-box;
display:-webkit-flex;
display:-ms-flexbox;
display:flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
-webkit-box-align: center;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
}
.footer-container {
width:85%;
height:inherit;
margin-top:60px;
overflow:hidden;
display:-webkit-box;
display:-webkit-flex;
display:-ms-flexbox;
display:flex;
-webkit-box-pack: justify;
-webkit-justify-content: space-between;
-ms-flex-pack: justify;
justify-content: space-between;
}
.footer-column {
min-width:20%;
max-width:20%;
margin-bottom:40px;
}
#column-1 {background-color:red}
#column-2 {background-color:yellow}
#column-3 {background-color:blue}
#column-4 {background-color:green}
@media only screen
and (min-width : 0px)
and (max-width : 980px) {
.footer-container {
-webkit-flex-wrap: wrap;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
-webkit-flex-direction: row;
-ms-flex-direction: row;
flex-direction: row;
}
.footer-column {
margin-bottom:50px;
min-width:45% !important;
max-width:45% !important;
}
}
1 个解决方案