我正在尝试使用在iPad上运行的flex模型进行非常简单的布局。
我有一个包含div,它应该以内容div为中心。
示例代码按照预期在iPad(视网膜)上的所有浏览器和平台上执行。
在线使用各种iPad模拟器不会复制问题。我只能在实际的iPad上复制它。这是一个截图:
非常感谢任何和所有建议。
CSS:
.container {
width: 510px;
height: 310px;
background: red;
display: flex;
display: -webkit-flexbox;
display: -ms-flexbox;
display: -webkit-flex;
flex-direction: row;
flex-wrap: wrap;
-webkit-box-pack: center;
-moz-box-pack: center;
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
-webkit-flex-align: center;
-ms-flex-align: center;
-webkit-align-items: center;
align-items:center;
border: 2px solid;
padding: 5px;
margin: 0;
}
.content {
float: left;
width: 150px;
height: 150px;
background: green;
border: 2px solid;
padding: 0;
margin: 0;
}
.content2 {
float: left;
width: 150px;
height: 150px;
background: blue;
border: 2px solid;
padding: 0;
margin: 0;
}
HTML:
<div class="container">
<div class="content">
<p>Content</p>
</div>
<div class="content2">
<p>Content2</p>
</div>
</div>
答案 0 :(得分:18)
你遗漏了旧的2009年草案中的一些属性(或者将它们命名为错误)。您的容器CSS应如下所示:
http://cssdeck.com/labs/ci9imeed
.container {
width: 510px;
height: 310px;
background: red;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-box-pack: center;
-moz-box-pack: center;
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
-webkit-box-align: center;
-moz-box-align: center;
-ms-flex-align: center;
-webkit-align-items: center;
align-items: center;
border: 2px solid;
padding: 5px;
margin: 0;
}
但请注意,没有一个采用2009 Flexbox实现的浏览器(Android,旧版Safari,旧版Firefox)都不支持包装。