我正在制作一张具有相同图像尺寸和文字的卡片。我已经给max-height了图片。但是图像大小不相等。我将在下面给出我的代码。我附上我的网站的快照,以获取更好的参考。在这个项目中,我正在使用HTML,CSS和BOOTSTRAP4
问题是:图像
.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;
}Run Code Online (Sandbox Code Playgroud)
<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 …Run Code Online (Sandbox Code Playgroud)我正在展示一系列像这样的 Bootstrap 4 卡......
<div class="row">
<!-- column -->
<div class="d-flex align-items-stretch col-xs-12 col-sm-6 col-md-4 col-lg-2 p-2">
<!-- card -->
<div class="card rounded-0 w-100 bg-white">
<a href="http://www.example.com/destination.html">
<img src="http://www.www.example.com/images/photo.jpg" class="card-img-top img-responsive w-100">
</a>
<div class="card-body">
<h6 class="card-title">Bookish Blaenavon opens new chapter</h6>
</div>
</div>
<!-- end card -->
</div>
<!-- end column -->
<! -- more of the same cards here +++ -->
</div>
Run Code Online (Sandbox Code Playgroud)
所有图像的尺寸可能不相等,但通过其类别.card-img-top,应以一致的尺寸显示。
宽度:
仅供参考 - 为了解决宽度问题,我已经添加.w-100了.card和img,尽管我认为后者可能是多余的。
另外,我的样式表适用object-fit: cover;于 …