html - 同一 div 中的响应式图像
问题描述
我有这个简单的脚本,其中有 2 个响应式图像。如果您最小化窗口,您将相应地显示图像。
但我将 2 张图片放在同一个 div 中,如下所示:
<div class="wrapper">
<div class="block">
<img
src=
"https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885__340.jpg"
></img>
<img
src=
"https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885__340.jpg"
></img>
</div>
</div>
我不会采取同样的效果,为什么?
解决方案
因为每个图像的宽度仍然为 100%。将宽度设置为 50% 会使它们再次缩放。还将高度设置为自动以保持比例。
请参见下面的示例:
.wrapper {
box-sizing: border-box;
display: flex;
justify-content: center;
border: solid red;
}
.block {
display: flex;
width: 100%;
border: solid blue;
}
.block img {
width: 50%;
max-width: 400px;
height: auto;
}
<div class="wrapper">
<div class="block">
<img src="https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885__340.jpg">
<img src="https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885__340.jpg">
</div>
</div>
推荐阅读
- php - 使用 Timber 显示子类别
- javascript - 如何使用新 div 附加 div 并将 var 放入该新 div
- c# - C# 代码问题 - 代码无法正常工作
- c - 我的代码中的循环和开关
- css - Grunt 运行任务取决于文件修改,有可能吗?
- google-app-engine - Google App Engine 是否支持通过 python 进行多处理,数据库是否支持本地主机中的多次写入?
- r - Ubuntu 安装 MongoDB 4.0.0 时自动卸载 R 语言包
- python-2.7 - 如何在 Python 中通过 Selenium 截取多个屏幕截图?
- spring-mvc - WebServerException:无法启动嵌入式 Tomcat | Spring Boot 尤里卡服务器
- c++ - 如何使用 qt 向 3D 网格缩放?