IE10中的Flexbox居中和溢出错误?

时间:2015-11-07 01:09:54

标签: css css3 flexbox internet-explorer-10

enter image description here

我想要做的基本上是有一个标题和一个容器总是居中,如果它们比屏幕小(身高100%)。如果内容和标题大于屏幕,则允许在其容器内滚动(注意标题不应该是可滚动的。)

我设法让它在Chrome中运行,但在IE10中却没有。这是JSFiddle。



var p = $('p');
$('button').click(function(){
	for(var i=0; i<30; i++){
        $('.content').append(p.clone());
    }
});
&#13;
.screen{
    border: 1px solid red;
    padding: 3px;
    height: 300px;
    display: flex; 
    display: -ms-flexbox; 
    justify-content: center; 
    -ms-flex-pack: center;
    flex-direction: column; 
    -ms-flex-direction: column;
}

.header{border: 1px solid blue; padding: 10px;}
.content{ border: 1px solid green; background: #aaa; overflow: auto;}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button>Add more content</button>
<div class="screen">
    <div class="header">
        Header
    </div>
    <div class="content">
        <p>This is the content</p>
    </div>
</div>
&#13;
&#13;
&#13;

http://jsfiddle.net/w8zg8hr2/2/

1 个答案:

答案 0 :(得分:2)

您需要将 flex: 0 1 auto; 添加到.content div,将 overflow: auto; 添加到.screen容器。 IE10使用2012语法,默认为flex: 0 0 auto而不是现代值flex: 0 1 auto;

&#13;
&#13;
var p = $('p');
$('button').click(function () {
    for (var i = 0; i < 30; i++) {
        $('.content').append(p.clone());
    }
});
&#13;
.screen {
    border: 1px solid red;
    padding: 3px;
    height: 300px;
    display: flex;
    display: -ms-flexbox;
    justify-content: center;
    -ms-flex-pack: center;
    flex-direction: column;
    -ms-flex-direction: column;
    overflow: auto;
}
.header {
    border: 1px solid blue;
    padding: 10px;
}
.content {
    border: 1px solid green;
    background: #aaa;
    overflow: auto !important;
    flex: 0 1 auto; /* Add this property value */
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button>Add more content</button>
<div class="screen">
    <div class="header">Header</div>
    <div class="content">
        <p>This is the content</p>
    </div>
</div>
&#13;
&#13;
&#13;

Win7 / IE10的Browserstack截图: