即使有前缀,Chrome 和 Safari 上的 CSS 问题

标签 css google-chrome flexbox vendor-prefix

我有这部分 CSS,我在 Chrome 和 Safari 上有问题,即使整个 CSS 文件已经用 Autoprefixer 作为前缀(并用 Pleeeease 双重检查)。任何线索为什么?它应该是 2 个盒子在行 (.deuxcases) 上有 flex 行为,每个盒子在列上有 flex 行为 (2 x .case),但在 Chrome 和 Safari 上它都是一条长长的困惑线,只在火狐。我使用 Chrome 50 和 Safari 8.0.2。谢谢

.deuxcases {
margin-top: 70px;
max-height: 60vh;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-box-orient:horizontal;
-webkit-box-direction:normal;
-webkit-flex-direction:row;
    -ms-flex-direction:row;
        flex-direction:row;
-webkit-flex-wrap:nowrap;
    -ms-flex-wrap:nowrap;
        flex-wrap:nowrap;
-webkit-box-pack:justify;
-webkit-justify-content:space-between;
    -ms-flex-pack:justify;
        justify-content:space-between;
}

.case {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-box-orient:vertical;
-webkit-box-direction:normal;
-webkit-flex-direction:column;
    -ms-flex-direction:column;
        flex-direction:column;
-webkit-box-pack:center;
-webkit-justify-content:center;
    -ms-flex-pack:center;
        justify-content:center;
-webkit-flex-wrap:wrap;
    -ms-flex-wrap:wrap;
        flex-wrap:wrap;
-webkit-box-flex:1;
-webkit-flex:1;
    -ms-flex:1;
        flex:1;
padding:auto;
margin:10%;
height: auto;
min-width: 25vw;
box-shadow: .5em .5em .5em .5em #aaa;
}

最佳答案

您应该始终尝试设置 heightwidth显式值而不是 auto .后者在浏览器中的工作方式不一致,这就是您为这种布局苦苦挣扎的原因。

只需在 .case 上设置高度即可类别为 100%而不是 auto ,它将按预期工作。

像这样:

.case {
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-orient:vertical;
    -webkit-box-direction:normal;
    -webkit-flex-direction:column;
        -ms-flex-direction:column;
            flex-direction:column;
    -webkit-box-pack:center;
    -webkit-justify-content:center;
        -ms-flex-pack:center;
            justify-content:center;
    -webkit-flex-wrap:wrap;
        -ms-flex-wrap:wrap;
            flex-wrap:wrap;
    -webkit-box-flex:1;
    -webkit-flex:1;
        -ms-flex:1;
            flex:1;
    padding:auto;
    margin:10%;
    height: 100%;
    min-width: 25vw;
    box-shadow: .5em .5em .5em .5em #aaa;
}

关于即使有前缀,Chrome 和 Safari 上的 CSS 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36916389/

相关文章:

html - 居中 li 和最后一个 child 的边距

html - 我可以通过哪些方式将图像置于类似网格的格式中?

google-chrome - 301重定向后如何防止chrome从磁盘缓存中加载index.html

google-chrome - 如何在Macvim中使用Chrome打开当前文件

html - 将标题、段落和图像放在一起

html - IE11 - 缩小到 50% 时出现布局问题

javascript - Bootstrap 自定义布局

firefox - Chrome、Firefox 和 Safari 不应用 XSLT? IE 确实如此!

html - 展开的 flex 盒元素之间的垂直边界

html - Flexbox 最佳填充