简体   繁体   English

Internet Explorer 未正确连续显示 div

[英]Internet Explorer not showing divs in a row correctly

I unfortunately have to support later versions of IE (10 + 9) and have a current setup with divs that appear correctly in all browsers except IE9.不幸的是,我必须支持更高版本的 IE (10 + 9),并且当前设置的 div 可以在除 IE9 之外的所有浏览器中正确显示。 I have 4 cards in a row, IE 10 shows ok but in IE 9 the layout appears as so:我连续有 4 张卡片,IE 10 显示正常,但在 IE 9 中,布局显示如下:

在此处输入图片说明

My code is as follows:我的代码如下:

.wrapper {
width: 1200px;
margin: auto;
}

.row {
display: -ms-flexbox;
display: flex;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
margin-right: -10px;
margin-left: -10px;
}

.row-show-4 {
width: 100%;
}

.card {
position: relative;
padding: 0 10px;
float: left;
width: 25%;
}

HTML Markup HTML 标记

<div class="wrapper">
  <div class="row row-show-4">
     <div class="card"></div>
     <div class="card"></div>
     <div class="card"></div>
     <div class="card"></div>
     ...
  </div>
</div>

I know flexbox does not read correctly in older versions of IE, but can't figure out if that is the reason the divs won't display correctly, or if there is a fallback where I can keep flexbox as well for the newer browsers.我知道 flexbox 在旧版本的 IE 中无法正确读取,但无法确定这是否是 div 无法正确显示的原因,或者是否有后备方法可以为较新的浏览器保留 flexbox。

I believe this should work.我相信这应该有效。 I don't have access to IE9 or IE10 so you need to test this yourself.我无权访问 IE9 或 IE10,因此您需要自己进行测试。

 .wrapper { width: 1200px; margin: auto; } @supports (display: -ms-flexbox) { .row { display: -ms-flexbox; margin-right: -10px; margin-left: -10px; } } @supports (display: flex) { .row { display: flex; margin-right: -10px; margin-left: -10px; } } .row-show-4 { width: 100%; } .card { position: relative; padding: 0 10px; float: left; /* Will be ignored in case of flexbox */ width: 25%; height: 50px; /* To make it visible */ background-color: gray; /* To make it visible */ }
 <div class="wrapper"> <div class="row row-show-4"> <div class="card"></div> <div class="card"></div> <div class="card"></div> <div class="card"></div> </div> <div class="row row-show-4"> <div class="card"></div> <div class="card"></div> <div class="card"></div> <div class="card"></div> </div> </div>

*{box-sizing: border-box;}
    .wrapper {width: 1200px;margin: auto;}
    .row-show-4 {width: 100%;column-count: 4;-webkit-column-count: 4;-moz-column-count: 4;column-count: 4;-webkit-column-gap: 20px;-moz-column-gap: 20px;column-gap: 20px;}
    .card{position:relative;padding:0 10px;width:100%;background:#c8c8c8;height:250px;margin-bottom:10px;display:inline-block;margin-top:10px;}

After using bootstrap reference, it seems that it works well in IE 9, code as below:使用 bootstrap 引用后,在 IE 9 中似乎运行良好,代码如下:

    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <style>
        .wrapper {
            width: 1200px;
            margin: auto;
        }

        .row {
            display: -ms-flexbox;
            display: flex;
            -ms-flex-wrap: wrap;
            flex-wrap: wrap;
            margin-right: -10px;
            margin-left: -10px;
        }

        .row-show-4 {
            width: 100%;
        }

        .card {
            position: relative;
            padding: 0 10px;
            float: left;
            width: 24%;
            background-color: gray;
            margin-top: 10px;
            margin-left: 10px;
        }
    </style>
    <div class="wrapper">
        <div class="row row-show-4">
            <div class="card">AA</div>
            <div class="card">BB</div>
            <div class="card">CC</div>
            <div class="card">DD</div>
            <div class="card">AA</div>
            <div class="card">BB</div>
            <div class="card">CC</div>
            <div class="card">DD</div>
            <div class="card">AA</div>
            <div class="card">BB</div>
            <div class="card">CC</div>
            <div class="card">DD</div>
        </div>
    </div>

The output like this:输出是这样的:

在此处输入图片说明

感谢大家的回复,我最终做的是为卡片设置一个高度,它可以解决单独显示在一行上的单独卡片。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM