html - 无法将图像放入网格卡内
问题描述
这应该是微不足道的,但我无法让图像适合响应网格内的卡片:这是 CSS:
body {
background-color: gery;
}
.cards {
margin: 0 auto;
max-width: 1000px;
display: grid;
grid-template-columns: repeat(auto-fill, minmax(225px, 1fr));
grid-auto-rows: auto;
gap: 20px;
padding-top: 30px;
}
.card {
background-color: #fff;
line-height: 1.5;
font-size: 1.1em;
padding: 15px;
background: #fafafa;
}
.card__image {
width: 100% !important;
height: 150px;
object-fit: cover;
display: block;
}
和 HTML
<div class="cards">
<div class="card">
<a href="#">
<img class="card__image" loading="lazy" src="https://fakeimg.pl/200x100/ff0000/">
</a>
<strong><a href="/#"> loerm ipsum</a></strong>
</div>
<div class="card">
<a href="#">
<img class="card__image" loading="lazy" src="https://fakeimg.pl/200x100/ff0000/">
</a>
<strong><a href="/#">bla blaxum</a></strong>
</div>
</div>
代码笔:
https://codepen.io/bcodus/pen/RwpGYaQ
请注意,img 周围有一个不应存在的边距。
感谢您帮助解决此问题。
解决方案
推荐阅读
- django - 通过ajax调用一次保存一行
- java - 杰克逊的“轻松”字段名称
- reactjs - 使用 webpack-dev-middleware 和 webpack-hot-middleware 的 react-error-overlay 不起作用
- authentication - 使用多个 ServiceStack 的身份验证提供程序会引发错误
- amazon-web-services - AWS - 如何将 DynamoDb 表数据传递给 Lambda 函数
- design-patterns - 如何设计一个发布订阅系统,其中同一实体可以有多个发布者?
- matlab - matlab中“内存不足”错误的解决方法
- selenium-webdriver - 从渲染器接收消息超时:9.999,截屏时
- python - 神经网络首先找到最佳超参数或架构
- tensorflow - AttributeError:模块“tensorflow.estimator”没有属性“SessionRunHook”