css - Bootstrap 4 如何重叠两个响应式堆叠的 Div

标签 css bootstrap-4 responsive-design

我是一名后端人员,正在尝试找出我们使用 Bootstrap 4 的元素的一些细节。

简单地说,我们要创建在这里执行的布局: https://codepen.io/mediumandmessage/pen/xVeXop

(这个示例和下面的代码来 self 找到的原始 Bootstrap 3 示例,而不是 Bootstrap 4)

HTML:

.somesection {margin-top:50px!important;}
body {
  font-size:17px;
  font-family:Helvetica Neue;
}
img {max-width:100%;}

.overlay-text {
  font-size:3.5vw;
  float:right;
  width:65%; /*important*/
  bottom:21vw; /*important*/
  padding: 25px;
  background:#f7f7f7;
}
<div class="container somesection">
  <div class="row col-xs-6">  
     <img src="https://images.unsplash.com/photo-1459664018906-085c36f472af?format=auto&auto=compress&dpr=1&crop=entropy&fit=crop&w=1087&h=725&q=80">
  </div>
  <div class="col-xs-3 col-sm-offset-4 overlay-text">
      This is some text that should partially overlay.
  </div>
</div>

但是,该示例使用 Bootstrap 3 并在 Bootstrap 4 中中断(文本水平显示在图像下方),并且也不会响应式地堆叠 div。

我尝试过使用绝对相对定位等。它变成了很多代码来干净地执行并做出响应,我希望有人在那里可能对在纯 Bootstrap4 中实现有一些见解...

如果有人可以在这里分享任何专业知识,我将不胜感激!

最佳答案

您可以向覆盖列添加转换(对于较小的屏幕,您可能需要使用媒体查询来取消此操作)。

请注意,在下面的 html 中,我已经修复了您的代码以与 boostrap 4 一起使用 - 列必须位于一行内(它们不能位于一行上),并且我认为没有 -xs 不再上课

.overlay-text {
  /* these two are needed - the align self makes the column not stretch the whole height of the image column and the translate moves the column over the image */
  align-self: flex-start;
  transform: translateX(-20%);

  /* the following are for example only */
  background-color: #ffffff;
  padding:20px;
}
<div class="container somesection">
  <div class="row">
    <div class="col col-sm-6">
      <img src="https://images.unsplash.com/photo-1459664018906-085c36f472af?format=auto&amp;auto=compress&amp;dpr=1&amp;crop=entropy&amp;fit=crop&amp;w=1087&amp;h=725&amp;q=80" class="w-100">
    </div>
    <div class="col col-sm-3 col-sm-offset-4 overlay-text">
      This is some text that should partially overlay.
    </div>
  </div>
</div>

Example bootply

关于css - Bootstrap 4 如何重叠两个响应式堆叠的 Div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57712205/

相关文章:

javascript - 如果我忽略 "coding nicely"并将 css(使用样式标签)和 js(使用脚本标签)代码放在一个 html 文件中会发生什么

css - 如何创建自定义单选按钮?

html - Bootstrap 轮播图片大小正在改变

html - 调整大小时 CSS float 时 ​​Chrome 中的响应错误

带有 Bootstrap 样式和响应式扩展的 jQuery DataTables 不起作用

html - :not(selector) isn't working properly

css - 当窗口缩小时,bootstrap 折叠栏变为透明

html - 为什么我在使用 bootstrap 的 css 文件时不能让我的导航栏元素向右浮动?

html - 无法通过 btn-group open 打开下拉按钮组

html - 如何为大于 767px 的更大屏幕应用 Bootstrap 表响应类