html - 改进 CLS 并拥有响应式图像
问题描述
我一直在努力改进网站上的 CLS。
所以我尝试添加一个父容器,以便图像将调整为该容器的大小。见下文:
.cls-parent {
width: 100%;
}
.cls-container {
display: block;
width: 100%;
height: auto;
position: relative;
overflow: hidden;
padding: 26.04% 0 0 0; /* 26.04% / (96 / 25) = 100 / (1900 / 500) */
}
.cls-container img {
display: block;
max-width:100%;
max-height:100%;
width: auto;
height: auto;
}
和 HTML:
<div class="cls-parent">
<div class="cls-container">
<img width="1900px" height="631" src="/wp-content/uploads/2020/11/Header_BlackFriday_v2_ENG.jpg">
</div>
</div>
但它不起作用,我不确定我做错了什么。
解决方案
推荐阅读
- visual-studio - 如何放大visual studio watch输出窗口
- asp.net-core - 无法访问服务结构服务
- git - 在 git 中复制和编辑文件会将整个文件显示为新更改
- ios - UIContextualAction 删除行问题。UIContextualAction 的菜单与单元格重叠
- sql - 表重命名时应该注意什么?
- mysql - SQL - 插入后创建触发器
- mongodb - 使用 mongodb 确保 N 个值为 X 的项目保留在数组中
- java - Tensorflow Java RNN-LSTM 重置状态
- apache-kafka - 如何将 kafka 主题迁移到日志压缩?
- python - 使用python selenium从HTML标签中提取属性