Bootstrap 4 IE 没有在 card-img-overlay 上使用 col-sm-12

jsP*_*yer 1 html css twitter-bootstrap bootstrap-4

我使用 bootstrap card-img-overlay 类创建了一个带有图像和文本叠加层的 cta。还添加了一个暗低不透明度的 div,使文本更亮。除 IE 11 外,所有浏览器都运行良好。

Q1: IE 中的列宽在哪里中断,我不认为是我的 css 导致了这部分。这是一个已知的引导程序 4 问题吗?

Q2: 如何修复覆盖 div 以显示在图像顶部,如 chrome 和其他浏览器。有没有更好的方法适用于两者?

打破 IE 图像 在此处输入图片说明

Chome 和其他运行良好的浏览器 在此处输入图片说明

.dnow-regionsContent .overlay-div {
    height: 100%;
    width: 100%;
    position: absolute;
    background-color: #000;
    opacity: 0.3;
}
.dnow-regionsContent img {
    max-height: 40rem;
}
Run Code Online (Sandbox Code Playgroud)
<!DOCTYPE html>
<html lang="en">

<head>
   <meta charset="UTF-8">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <meta http-equiv="X-UA-Compatible" content="ie=edge">
   <title>slick slider</title>
   <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
      crossorigin="anonymous">


   <link rel="stylesheet" href="css/style.css">
</head>

<body>
   <section class="dnow-regionsWrap">
      <div class="dnow-regionsContent">
         <div class="card bg-dark text-white">
            <img src="https://www.dropbox.com/s/9fvw247x7ml90mf/canadaN.jpg?dl=1" alt="">
            <div class="overlay-div"></div>
            <div class="card-img-overlay d-flex align-items-center container">
               <div class="row  mb-5">
                  <div class=" col-sm-12 text-content">
                     <h2 class="card-title ">
                        Canada
                     </h2>
                     <p class="">
                        Viewl all Location Viewl all Location
                     </p>
                  </div>
               </div>
            </div>
         </div>
      </div>
   </section>

   <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
      crossorigin="anonymous"></script>
   <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
      crossorigin="anonymous"></script>
   <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
      crossorigin="anonymous"></script>

</body>

</html>
Run Code Online (Sandbox Code Playgroud)

div*_*993 5

实际原因:

col-sm-12,但d-flexcard-img-overlay使您的设计看起来在IE中不妥当的。

为什么?

display:flex应用于元素时,直接子元素(即弹性项目)需要指定一些宽度,否则它们不会像我们需要的那样扩展或占用足够的空间,除非内容不够。

在您的情况下,我们一直d-flex在,card-img-overlay因此它的直接子项(即弹性项目).row不会有100%宽度。现在对于col-sm-12列,100%将是完整的水平空间,其父级 ( .row) 本身不够宽。这才是真正的问题。

解决方案:

  1. 100%宽度.row,你可以使用 Bootstrap 4 的类w-100
    • 这可能是您的问题/查询的真正解决方案,但仍然需要很少的事情来获得您想要的外观,因为您在其他浏览器中拥有它。
  2. 给予position: absolute不能单独工作,智能浏览器会知道该怎么做,但其他浏览器需要像top&这样的偏移值left。在您的情况下,值为0.
  3. 最后用实际尺寸属性的图像widthheight<img>,你的情况的标签,这将是width="1200"height="800"

所以基本上 bootstrap 与这个问题无关,它只是标记和 CSS 属性的流程。

边注:

我希望上述步骤可以帮助您清除问题或理解它。我建议始终拥有标签的widthheight属性,<img>以便浏览器(旧浏览器)知道在页面上制作特定大小的块。

.dnow-regionsContent .overlay-div {
    height: 100%;
    width: 100%;
    position: absolute;
    background-color: #000;
    opacity: 0.3;
    /*Added*/
    top:0;
    left:0;
}
.dnow-regionsContent img {
    max-height: 40rem;
}
Run Code Online (Sandbox Code Playgroud)
<!DOCTYPE html>
<html lang="en">

<head>
   <meta charset="UTF-8">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <meta http-equiv="X-UA-Compatible" content="ie=edge">
   <title>slick slider</title>
   <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
      crossorigin="anonymous">


   <link rel="stylesheet" href="css/style.css">
</head>

<body>
   <section class="dnow-regionsWrap">
      <div class="dnow-regionsContent">
         <div class="card bg-dark text-white">
            <img src="https://www.dropbox.com/s/9fvw247x7ml90mf/canadaN.jpg?dl=1" width="1200" height="800" alt="">
            <div class="overlay-div"></div>
            <div class="card-img-overlay d-flex align-items-center container">
               <div class="row mb-5 w-100">
                  <div class=" col-sm-12 text-content">
                     <h2 class="card-title ">
                        Canada
                     </h2>
                     <p class="">
                        Viewl all Location Viewl all Location
                     </p>
                  </div>
               </div>
            </div>
         </div>
      </div>
   </section>

   <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
      crossorigin="anonymous"></script>
   <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
      crossorigin="anonymous"></script>
   <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
      crossorigin="anonymous"></script>

</body>

</html>
Run Code Online (Sandbox Code Playgroud)

不是你,是IE。

希望这对你有帮助!