Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
394 views
in Technique[技术] by (71.8m points)

html - align-items, align-self not working on IE11

I have a simple plunker here.

.container {
  display:flex;
  flex-flow: row nowrap;
  justify-content: space-between;
  align-items: center;
  min-height: 4em;
}

.nav {      
  flex: 0 0 4em;
  height: 1em;
}

.logo {
  flex: 1 0 auto; 
  align-self: stretch;
}

This is working how I want it to in Chrome 49:

enter image description here

But not in IE11:

enter image description here

I have checked that IE isn't in compatability mode - it's not - it's in IE11 mode.

What's going on here?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is a bug in IE11.

The min-height property on a flex container isn't recognized by flex items in IE11.

If you switch to height: 4em, you'll see that your layout works.

A simple workaround is to make .container a flex item.

In other words, add this to your code:

body {
    display: flex;
}

.container {
    width: 100%; /* or flex: 1 */
}

For whatever reason, by making your flex container also a flex item, the min-height rule is respected by the child elements.

More details here: Flexbugs: min-height on a flex container won't apply to its flex items


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...