我是一名后端人员,正在尝试找出我们使用 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&auto=compress&dpr=1&crop=entropy&fit=crop&w=1087&h=725&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>
关于css - Bootstrap 4 如何重叠两个响应式堆叠的 Div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57712205/