css - 有没有办法使用 css 制作一个尺寸的图像?
问题描述
问题是我希望容器中的图像大小相同,但我得到的是容器增长或缩小以适应图像或从容器中伸出的图像。
<div class="grid-container">
<article class="card">
<div class="content">
<h4>Title</h4>
<p>something about the website</p>
</div>
<div class="img-box">
<a href="#"><img src="./img/work-1.jpg" alt="">
</a>
</div>
</div>
.grid-container {
display: grid;
}
.card {
display: grid;
grid-template-columns: repeat(2, 1fr);
background-color: aqua;
margin: 1rem 0;
padding: 0.5rem;
align-items: start;
justify-items: start;
}
.card img {
display: block;
}
.img {
max-width: 100%;
}
解决方案
这可能会帮助你
img{
height: auto;
width: 100%;
}
推荐阅读
- vue.js - 是否可以在 vue.config.js 中设置多个基本 url?
- ios - Swift 4.2:如何在 ViewController 中嵌入 UIPageControl(没有 Storyboard)?
- testing - 在功能自动化中处理输入和输出?
- java - java类属性的设置值范围
- android - 黑屏后我的应用程序崩溃
- excel - Excel计算跨越一年的两个日期之间每个月的天数
- delphi - 升级后的自定义组件无法编译
- android - 返回导航控制器的状态(Android导航组件)
- javascript - JavaScript 将字符串转换为 HTML 元素
- angular - 对象不是函数。network.ts 中的错误