CSS Masonry 类型图像布局响应

标签 css

我需要创建一个响应式 Masonry 图像布局,但有 2 个大部分会让它变得非常棘手?

见附图:

enter image description here

我怎样才能得到类似但响应迅速的东西?

最佳答案

您可以尝试使用列来实现这一点。

HTML

<section id="photos">
  <img src="images/image-1.jpg" alt="Some Image">
  <img src="images/image-2.jpg" alt="Another Image">
  ...
</section>

CSS

#photos {
  /* Prevent vertical gaps */
  line-height: 0;
  -webkit-column-count: 3;
  -webkit-column-gap:   10px;
  -moz-column-count:    3;
  -moz-column-gap:      10px;
  column-count:         3;
  column-gap:           10px;  
}

#photos img {
  /* Just in case there are inline attributes */
  width: 100% !important;
  height: auto !important;
}

还有一些媒体查询CSS

@media (max-width: 800px) {
  #photos {
  -moz-column-count:    2;
  -webkit-column-count: 2;
  column-count:         2;
 }
}
@media (max-width: 400px) {
  #photos {
  -moz-column-count:    1;
  -webkit-column-count: 1;
  column-count:         1;
 }
}

这是本文中的更多信息 Seamless Responsive Photo Grid

关于CSS Masonry 类型图像布局响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33166508/

相关文章:

javascript - 需要图像幻灯片放映方面的帮助吗?

css - 我的 Logo 在导航栏上模糊不清,在桌面 View 中看起来很小

html - 在 bootstrap 中对齐 list-group-item 中的 3 个元素

css - 为什么我的选择菜单位于相应标签的下方?

css - 添加具有优先级的动态自定义样式在 wordpress 中不起作用

html - 为什么我的 html/css 代码不能创建按钮?

css - Font Awesome 加载速度非常慢

html - 更改 HTML 符号的字体颜色

javascript - 围绕轴点旋转SVG中的泪珠形状

html - Bootstrap 表中标题下方的灰线