html - 具有 2 列和不同高度的水平卡片

标签 html css

我对卡片的 2 列有疑问,其中左侧是图像,右侧是文本。但是我想让“右栏”的高度比“图像栏”的高度小3/4,并且位置在“左栏”的中间,按钮位置总是在右卡的底部(固定位置)甚至卡片中的文字也不多。

我试过下面的代码,但它不符合我的需要

https://jsfiddle.net/n0p4tbo9/

HTML

<div class="container-fluid">
    <div class="row">
        <div class="col-12 mt-3">
            <div class="card">
                <div class="card-horizontal">
                    <div class="img-square-wrapper">
                        <img class="" src="http://via.placeholder.com/300x180" alt="Card image cap">
                    </div>
                    <div class="card-body">
                        <h4 class="card-title">Card title</h4>
                        <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
                        <button>Learn More</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

CSS

.card-horizontal {
    display: flex;
    flex: 1 1 auto;
}

我希望输出应该像这张图 https://imgur.com/ddblXo3

最佳答案

您应该尝试使用 display: grid; 而不是 display: flex;。在水平和垂直定位元素方面,网格比 flex 好得多。

这里有一个你的 fiddle 的分支作为例子:https://jsfiddle.net/0hf51xaL/

关于html - 具有 2 列和不同高度的水平卡片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58356008/

相关文章:

html - 如何在素材 UI 芯片中显示姓名和电子邮件?

html - 在溢出元素中具有绝对位置的嵌套元素渗出并显示

jquery 没有到达 css 类

html - 在 DIV 内水平对齐 DIV - IE 不工作

html - 使用标签和单选按钮作为 CSS 钩子(Hook)是否适合 HTML?

jquery - 使用响应式和 HTML5 在后台播放视频

css - 用 5 个叶子创建一个 css 花

javascript - LessCss 和 css 导入

html - 并排漂浮

javascript - 在 HTML 表格上启用垂直滚动