27

为什么以下代码在 IE10 中不起作用?

.foo {
    display: -ms-flex; 
    -ms-justify-content: center;
}

为了让他们工作,我需要写什么?

4

2 回答 2

49

IE10 从2012 年 3 月开始实施 Flexbox 草案。这些属性对应于这些:

.foo {
    display: -ms-flexbox;
    -ms-flex-pack: center;
}
于 2013-07-17T10:11:45.273 回答
24

尝试为所有浏览器获取正确语法时,一个很好的起点是http://the-echoplex.net/flexyboxes/

要在容器中水平和垂直居中元素,您将获得如下代码:(在 Chrome、FF、Opera 12.1+ 和 IE 10+ 中工作)

小提琴

<div class="flex-container">
  <div class="flex-item">A</div>
  <div class="flex-item">B</div>
  <div class="flex-item">C</div>
</div>

CSS

.flex-container {

    height: 100%;
    display: -webkit-box;
    display: -moz-box;
    display: -ms-flexbox;
    display: -webkit-flex;
    display: flex;
    -webkit-box-direction: normal;
    -moz-box-direction: normal;
    -webkit-box-orient: horizontal;
    -moz-box-orient: horizontal;
    -webkit-flex-direction: row;
    -ms-flex-direction: row;
    flex-direction: row;
    -webkit-flex-wrap: wrap;
    -ms-flex-wrap: wrap;
    flex-wrap: wrap;
    -webkit-box-pack: center;
    -moz-box-pack: center;
    -webkit-justify-content: center;
    -ms-flex-pack: center;
    justify-content: center;
    -webkit-align-content: stretch;
    -ms-flex-line-pack: stretch;
    align-content: stretch;
    -webkit-box-align: center;
    -moz-box-align: center;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
    }
.flex-item
{
    width: 100px;
    height:100px;
    background: brown;
    margin: 0 10px;
}

/*
    Legacy Firefox implementation treats all flex containers
    as inline-block elements.
*/

@-moz-document url-prefix() {
.flex-container {
    width: 100%;
    -moz-box-sizing: border-box;
    }

}
于 2013-07-17T10:20:52.330 回答