MONDAY 5TH JUNE, 2017
I have the following code which has four columns wrapped over 2 rows using flex. In chrome and firefox, this works perfectly with the first item taking it's own row and then the second row, all the items match the tallest in that row.
我有下面的代码,用flex将四列封装在两行之上。在chrome和火狐浏览器中,第一个条目拥有自己的行,然后是第二行,所有条目都匹配这一行中最高的。
However in IE11, the items in the second row match the tallest item out of all 4 (rather than just on it's own row) meaning that there is a lot of white space created in the second row.
然而,在IE11中,第二行中的条目匹配了所有4个条目中最高的条目(而不仅仅是在它自己的行上),这意味着在第二行中创建了大量的空白。
* {
box-sizing: border-box;
}
img {
display: block;
width: 100%;
}
.grid-container {
padding-left: 0;
padding-right: 0;
margin-right: 0;
margin-left: 0;
display: flex;
flex-direction: row;
flex-wrap: wrap;
flex: 0 1 auto;
}
.grid-column {
padding-right: 12px;
padding-bottom: 24px;
padding-left: 12px;
flex-basis: 100%;
flex: 0 0 auto;
max-width: 100%;
margin-left: 0;
margin-right: 0;
flex-direction: column;
display: flex;
}
.grid-column:nth-child(1) {
min-width: 100%;
max-width: 100%;
}
.grid-column:nth-child(2) {
min-width: 50%;
max-width: 50%;
}
.grid-column:nth-child(3),
.grid-column:nth-child(4) {
min-width: 25%;
max-width: 25%;
}
.grid-column:nth-child(1) {
min-width: 100%;
max-width: 100%;
}
.widget-article {
display: flex;
flex-direction: column;
flex-grow: 1;
}
.grid-column:nth-child(1) .widget-article {
flex-direction: row;
}
.widget-article__content {
background: #313B3D;
color: #ffffff;
flex-grow: 1;
}
.widget-article__content a {
color: #ffffff;
}
MONDAY 5TH JUNE, 2017
MONDAY 5TH JUNE, 2017
MONDAY 5TH JUNE, 2017
MONDAY 5TH JUNE, 2017
Is there a way to make IE behave like chrome and firefox without changing the html structure?
有没有一种方法可以让IE像chrome和firefox一样不改变html结构?
1
You can replace flexbox for most elements except .container
using display: table
. Result:
除了.container之外,您可以使用display: table替换flexbox中的大多数元素。结果:
* {
box-sizing: border-box;
}
img {
display: block;
width: 100%;
}
.grid-container {
padding-left: 0;
padding-right: 0;
margin-right: 0;
margin-left: 0;
display: flex;
flex-direction: row;
flex-wrap: wrap;
flex: 0 1 auto;
}
.grid-column {
padding-right: 12px;
padding-bottom: 24px;
padding-left: 12px;
max-width: 100%;
margin-left: 0;
margin-right: 0;
}
.grid-column:nth-child(1) {
min-width: 100%;
max-width: 100%;
}
.grid-column:nth-child(2) {
min-width: 50%;
max-width: 50%;
}
.grid-column:nth-child(3),
.grid-column:nth-child(4) {
min-width: 25%;
max-width: 25%;
}
.grid-column:nth-child(1) {
min-width: 100%;
max-width: 100%;
}
.widget-article {
display: table;
height: 100%;
}
.widget-article > * {
display: table-row;
}
.grid-column:first-child .widget-article > * {
display: table-cell;
vertical-align: top;
}
.widget-article__content {
background: #313B3D;
color: #ffffff;
height: 100%;
}
.widget-article__content a {
color: #ffffff;
}
MONDAY 5TH JUNE, 2017
MONDAY 5TH JUNE, 2017
MONDAY 5TH JUNE, 2017
MONDAY 5TH JUNE, 2017
1
The problem in IE11 is that it uses the intrinsic height of the image.
IE11的问题在于它使用了图像的固有高度。
Although you've set the width of the image containers:
虽然您已经设置了图像容器的宽度:
.grid-column:nth-child(1) {
min-width: 100%;
max-width: 100%;
}
.grid-column:nth-child(2) {
min-width: 50%;
max-width: 50%;
}
.grid-column:nth-child(3),
.grid-column:nth-child(4) {
min-width: 25%;
max-width: 25%;
}
... which is enough to get the layout to work in Chrome and Firefox, these rules are not enough to alter the image's natural dimensions in IE11.
…这足以让布局在Chrome和Firefox中运行,但这些规则还不足以改变图片在IE11中的自然尺寸。
So consider adding something like this to your code:
因此,考虑在代码中添加如下内容:
/* pixel units for illustration purposes only */
.grid-column:nth-child(2) img {
height: 250px;
}
.grid-column:nth-child(3) img,
.grid-column:nth-child(4) img {
height: 125px;
}
jsFiddle demo
jsFiddle演示
Percentage heights are probably preferable to pixels, but that will take some work setting heights on ancestors. Since I don't know exactly what you want, I just used pixels for the demo. There may also be other sizing options you can use.
百分比高度可能比像素更高,但这需要对祖先进行一些设置。因为我不知道你想要什么,我只是用像素来演示。您还可以使用其他的分级选项。
But the bottom line is, you need to override the intrinsic dimensions of the image for the layout to work in IE11.
但最重要的是,你需要覆盖图像的固有维度,以便布局在IE11中工作。