html - 自动调整/裁剪 bootstrap col 中图像的高度,使其等于另一个 col 的高度

标签 html css twitter-bootstrap bootstrap-4

我有一个包含 2 列的 boostrap 行,左列包含一些文本,右列包含图像。

我想将右列的最大高度设置为等于左列的高度 - 这可能会因窗口大小的调整而改变(具有 min-height 属性)。

我想裁剪我认为可以在 css 中使用“object-fit:cover”实现的图像

我的代码如下:

<div class="row" id="test-row">
    <div class="col-2" id="test-left">
        Some random text
    </div>
    <div class="col-10" id="test-right">
        <img src="img_source" class="img-responsive">
    </div>
</div>

我看过在线和其他帖子,但似乎都基于不需要裁剪或缩小的列。

最佳答案

如果您愿意将您的图像作为背景图像,这是可能的。

<style>
     #bg-image {
        background-image: url('example.jpg');
        background-position: center;
        background-size: cover;
        background-repeat: no-repeat;
        width: 100%;
        height: 100%;
     }
</style>
<div class="row" id="test-row">
    <div class="col-2" id="test-left">
            Some random text
    </div>
    <div class="col-10" id="test-right">
        <div id="bg-image"></div>
    </div>
</div>

否则使用 javascript 窗口调整大小事件来设置高度。

关于html - 自动调整/裁剪 bootstrap col 中图像的高度,使其等于另一个 col 的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57773443/

相关文章:

html - 旋转具有变换原点的对象在 Firefox 中不起作用

css - Bootstrap : divide page contain in two(equal)

css - css 样板文件和框架有什么区别?

jquery - 在 Bootstrap 中安装 jQuery 插件时遇到问题

twitter-bootstrap - Bootstrap 3 向面板标题添加控件

html - 固定在 chrome mobile 上的位置导致元素在向上/向下滚动时移动

javascript - 为什么这个 JS 循环不能从函数内部返回变量

javascript - 如何使javascript显示用户鼠标单击的表的索引

html - 如何在移动模式下拆分 Bootstrap 列

javascript - 将元素平稳地移动到新位置而无需手动设置其位置