css - 用于图像布局问题的 CSS
问题描述
我正在学习响应式 CSS,所以这对我来说都是全新的。但是,为什么第二行的图像没有拥抱顶部的图像?
理想情况下,我每行只需要 4 张图像,但如果在较小的屏幕或手机等上,它将动态减小图像大小并减少每行的图像数量。似乎无法使其正常工作?任何帮助表示赞赏!与图像相关的所有 CSS 都在该静态页面上。
div.gallery {
border: 1px solid #ccc;
}
div.gallery:hover {
border: 1px solid #777;
}
div.gallery img {
width: 100%;
height: auto;
}
div.desc {
padding: 10px;
text-align: center;
}
* {
box-sizing: border-box;
}
.responsive {
padding: 0 6px;
float: right;
width: 24.99999%;
}
@media only screen and (max-width: 700px) {
.responsive {
width: 49.99999%;
margin: 6px 0;
}
}
@media only screen and (max-width: 500px) {
.responsive {
width: 100%;
}
}
.clearfix:after {
content: "";
display: table;
clear: both;
}
<div class="responsive">
<div class="gallery">
<a target="_blank" href="https://memorybox.pt">
<img src="images/memory-box.png" alt="Algarve Wedding Photography" width="600" height="400">
</a>
<div class="desc">Algarve Wedding Planners</div>
</div>
</div>
<div class="responsive">
<div class="gallery">
<a target="_blank" href="https://algarvedjhire.com/">
<img src="images/algarve_dj_hire.jpg" alt="Algarve Wedding Photography" width="600" height="400">
</a>
<div class="desc">Algarve DJ & Music</div>
</div>
解决方案
在你的 .responsive 类中使用高度而不是浮动右使用浮动左。请参见下面的示例。我使用高度 290px,您可以根据需要使用。
.responsive {
padding: 0 6px;
float: left;
width: 24.99999%;
height: 290px;
}
您也可以在响应断点中使用 margin-bottom ,使其看起来不错。请参见下面的示例。
@media only screen and (max-width: 700px) {
.responsive {
width: 49.99999%;
margin: 6px 0 30px 0;
}
}
推荐阅读
- c# - 在 C# 中使用 Web 服务:删除 Task.Wait()
- java - 可装入给定托盘的最大箱子 [箱子和托盘尺寸由用户定义]
- javascript - 为什么我会收到此错误“未经检查的 runtime.lastError:无法建立连接。接收端不存在。” 关于 ?
- android - 从服务启动应用程序(Flutter:Android)
- c++ - 迭代地从二叉搜索树中删除节点
- masstransit - Masstransit 如何在自定义过滤器中获取 ILifetimeScope
- python-3.x - 如何使用python 3解密aws lambda中的环境变量
- python-3.x - 打开和关闭窗口
- git - 如何删除我从上游/开发到功能分支的提交?
- node.js - node-pre-gyp info 此节点实例不支持 N-API 版本 3 的构建