ios - iPad 上的 CSS 灵活框布局

标签 ios css ipad flexbox

我正在尝试使用在 iPad 上工作的 flex 模型获得一个非常简单的布局。

我有一个包含 div,它应该使内容 div 居中。

示例代码在除 iPad (retina) 之外的所有浏览器和平台上都按预期运行。

在线使用各种 iPad 模拟器不会重现该问题。我只能在实际的 iPad 上复制它。这是它的截图:

enter image description here

我们将不胜感激任何和所有建议。

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>

最佳答案

您遗漏了 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)支持换行。

关于ios - iPad 上的 CSS 灵活框布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19028531/

相关文章:

ios - XCODE 6/Swift - 是否可以在未发布的 IOS 应用程序上预览 admobs?

ios - MKMapView 不读取给定的坐标

ios - iOS 上的 Flurry 和完整堆栈跟踪

javascript - 打印 HTML 页面(整页!)

iphone - 展开和折叠动画在 ios6 中不起作用

ios - 为数组中的新项目指定 indexPath.row

jquery - Bootstrap 3 : fixed column with responsive column

javascript - 如何防止输入元素在父 div 中移动?

iphone - NSString 中有setwidth 吗?

ios - 更改 MPVolumeView iPad 弹出框大小