html - 当我给出最大高度时,卡片图像宽度不相等

标签 html css bootstrap-4

我正在制作一张图片大小和文字相同的卡片。 我已经为图像提供了 max-height。但是图像大小不相等。 我将在下面给出我的代码。 我附上了我网站的快照,以便更好地引用。 在这个元素中,我使用了 HTML、CSS 和 BOOTSTRAP4

问题是:Image

  .kbcard {
        box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
        max-width: 300px;
        margin: auto;
        text-align: center;
        font-family: arial;
    }

    .kbtitle {
        color: grey;
        font-size: 18px;
    }

    a .kb{
        text-decoration: none;
        font-size: 22px;
        color: black;
    }
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
 

<div class="row">
    <div class="col-md-3">
        <div class="kbcard">
            <img src="https://www.saintleuparis.catholique.fr/IMG/arton691.jpg?1467978372" alt="John" style="max-width:300px">
            <h1>John Doe</h1>
            <p class="kbtitle">CEO & Founder, Example</p>
            <p>Harvard University</p>

        </div>

    </div> 
    <div class="col-md-3">
        <div class="kbcard">
            <img src="https://www.saintleuparis.catholique.fr/local/cache-vignettes/L187xH270/images-74-b67fc.jpg?1468002198" alt="John" style="max-width:300px">
            <h1>John Doe</h1>
            <p class="kbtitle">CEO & Founder, Example</p>
            <p>Harvard University</p>

        </div>

    </div>
     
</div>

我需要:Snap

最佳答案

 img {
        vertical-align: middle;
        border-style: none;
        width: 100%;
        height: 250px;
        object-fit: cover;
    }

尝试将这些样式添加到您的图片标签中

关于html - 当我给出最大高度时,卡片图像宽度不相等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56437535/

相关文章:

html - 从内部div继承高度到外部div

html - 如何将 3 个独立的 XSLT 文件从单个 XML 处理为单个输出?

html - 使用 CSS 网格的移动 Web 应用程序布局 - 如何使行灵活?

html - 奇怪的重复 IE div

javascript - 使用 Jquery 连续淡化缩略图列表(始终只显示 4 个?)

html - 内联样式决定标题高度,导致 Logo 上方和下方的填充

javascript - 减少客户端编译

html - Bootstrap4控制inline-form的宽度

css - 标签和输入在表单组的同一行

html - 菜单和垂直导航栏之间的额外空间