问题
Flex-end working for chrome and firefox, but not working for ie, go through following code
.flex-container { display: flex;
flex-wrap: nowrap;
background-color: DodgerBlue; flex-direction: column;flex-flow:column;
justify-content: flex-end;height:100px
}
<h1>Flexible Boxes</h1>
<div class="flex-container">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
</div>
<p>Try to resize the browser window.</p>
<p>A container with "flex-wrap: nowrap;" will never wrap its items.</p>
<p><strong>Note:</strong> Flexbox is not supported in Internet Explorer 10 or earlier versions.</p>
回答1:
IE seems to align items differently using justify-content
when there is an overflow. it doesn't only happen with flex-end
, you will face the same using center
. Any value that will create a top overflow will not work as expected.
It will also happen in a row direction. Any property that will create a left overflow will not work.
Examples where the alignment is doing nothing:
.container {
display:inline-flex;
height:50px;
width:50px;
margin:50px;
border:2px solid green;
}
.container span {
flex-shrink:0;
width:200%;
background:red;
}
.alt {
flex-direction:column;
}
.alt span {
height:200%;
width:auto;
}
<div class="container" style="justify-content:flex-end;">
<span></span>
</div>
<div class="container" style="justify-content:center;">
<span></span>
</div>
<div class="container alt" style="justify-content:flex-end;">
<span></span>
</div>
<div class="container alt" style="justify-content:center;">
<span></span>
</div>
I am surprised to say this, but it seems that IE is doing a good thing in those cases because it's preventing the unwanted overflow which may create issues like described in this question Centered flex-container grows beyond top and also this one Can't scroll to top of flex item that is overflowing container
Considering this, it's difficult to say if it's a bug. It's a probably by design and the IE team made the decision to avoid the bad overflow. 1
This said, here is a hack using some negative margin that will allow you to have the needed behavior on IE:
.flex-container {
display: flex;
flex-wrap: nowrap;
background-color: DodgerBlue;
flex-direction: column;
flex-flow: column;
justify-content: flex-end;
height: 100px
}
.flex-container > div:first-child {
margin-top:-100vh; /*put a very big margin here*/
}
<h1>Flexible Boxes</h1>
<div class="flex-container">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
</div>
Same hack applied to the previous examples:
.container {
display:inline-flex;
height:50px;
width:50px;
margin:50px;
border:2px solid green;
}
.container span {
flex-shrink:0;
width:200%;
background:red;
}
.alt {
flex-direction:column;
}
.alt span {
height:200%;
width:auto;
}
<div class="container" style="justify-content:flex-end;">
<span style="margin-left:-100%;"></span>
</div>
<div class="container" style="justify-content:center;">
<span style="margin: 0 -100%;"></span>
</div>
<div class="container alt" style="justify-content:flex-end;">
<span style="margin-top:-100%;"></span>
</div>
<div class="container alt" style="justify-content:center;">
<span style="margin:-100% 0;"></span>
</div>
1: I don't have any official proof at the time being.
回答2:
Try adding more display support:
.flex-container { display: flex;
flex-wrap: nowrap;
background-color: DodgerBlue; flex-direction: column;flex-flow:column;
justify-content: flex-end;height:100px
}
.flex-container {
/* Add more browser support */
display: flex;
display: -ms-flexbox;
display: -webkit-flex;
/* Combined flex-wrap and flex-direction */
flex-flow: nowrap column;
/* Add more browser support */
justify-content: flex-end;
-webkit-justify-content: flex-end;
/* This could potentially help with IE10+11 */
-ms-flex-pack: end;
justify-content: space-between;
height:100px
background-color: DodgerBlue;
height:100px
}
http://the-echoplex.net/flexyboxes/ Gives quite a few tips.
回答3:
just try to use
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
in your class like this
.wrapper {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
}
hope this will help you...
回答4:
You could refer to the following code, it seems that the flex-end works well on my side:
<style>
.flex-container {
display: flex;
flex-wrap: nowrap;
justify-content: flex-end;
background-color: DodgerBlue;
height: 100%;
flex-direction: column;
flex-flow: column;
}
.flex-container > div:nth-child(2n+0) {
background-color: aquamarine;
width: 300px;
height: 30px
}
.flex-container > div:nth-child(2n+1) {
background-color:antiquewhite;
width: 300px;
height: 30px
}
</style>
<h1>Flexible Boxes</h1>
<div class="flex-container">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
</div>
<p>Try to resize the browser window.</p>
<p>A container with "flex-wrap: nowrap;" will never wrap its items.</p>
<p><strong>Note:</strong> Flexbox is not supported in Internet Explorer 10 or earlier versions.</p>
The result as below:
回答5:
Flex and IE is a common problem. Most of the times this is related to the parent of the flex element. The parent is missing in the question, but you should do something like this:
HTML
<div class"flex-wrapper">
<div class="flex-container">...</div>
</div>
CSS
.flex-wrapper { width: 100%; }
What is important is that you use %
and do not use the px
unit.
来源:https://stackoverflow.com/questions/55058700/justify-content-flex-end-not-working-for-ie