css - 使用css网格在移动视图中拉伸的图像
问题描述
我使用 css 网格放置图像,在桌面上它看起来正确,但在 mobil 上它是垂直拉伸的。我设置了另一个尺寸相同的图像,可以正确显示。一切都设置相同。请在下面找到两个图像的 css 代码。我对图像名称 cic-img 有疑问。voc-img 显示正确。
.voc {
display:grid;
grid-template-columns: repeat(4, 25%);
grid-template-rows: max-content(30%) auto max-content(33%);
grid-gap: 10px;
margin: 9rem auto;
padding: 0 4rem;
width: 850px;
text-align: center;
overflow:hidden;
}
.voc-img {
grid-column: 2 / 4;
grid-row: 1/ 4;
width: 100%;
max-height: 100%;
}
.cic {
display: grid;
grid-template-columns: repeat(4, 25%);
grid-template-rows: max-content(30%) auto max-content(33%);
grid-gap: 10px;
margin: 9rem auto;
padding: 0 4rem;
width: 850px;
text-align: center;
overflow: hidden;
}
.cic-img {
grid-column: 2 / 4;
grid-row: 1/ 4;
height: 100%;
width:100%;
}
解决方案
在您的 CSS 中,我可以看到您的.cic-img
和.voc-img
没有相同的高度属性(max-height: 100%
vs height: 100%
)。这很可能解释了为什么这两个图像没有以相同的方式呈现。
考虑将.cic-img
's替换height: 100%
为max-height: 100%
,这样它的高度就不会被强制为 100%。
object-fit
顺便说一句, CSS 属性应该是有帮助的,而不是玩弄宽度和高度。
推荐阅读
- informix - 如何在 Informix 数据库中创建用户并限制会话数
- angular - 根据条件动态加载不同的组件
- python - 如何抓取受密码保护的网站
- node.js - Nodemailor 无法跨域发送邮件
- java - 如何在 Java 1.6 中将 UTC 日期转换为本地日期
- angular - PrimeNG TurboTable 排序图标在启用默认排序的情况下不可见
- architecture - DAO 层应该如何实现?一张表 DAO 还是多表 DAO?
- vhdl - VHDL为信号名称分配一个数字
- java - 关闭桌面/本机窗口的Java代码?
- c++ - 在模板实例化中包括和排除类型