首页 > 解决方案 > 图像布局(可变宽度,每行等高)

问题描述

我正在尝试创建一个网格布局,其中图像自动调整为相同的高度但不同的宽度以均匀地适合一条线。

目前我有这个:布局

但是正如您所看到的,这并不能使图像正确匹配。

<style>
img {
  vertical-align: middle;
  max-width: 100%;
}

.masonry {
  display: flex;
  width: 100%;
}

.masonry--h {
  flex-flow: row wrap;
}

.masonry--h {
  margin-left: -8px; 
  /* counter-reset: brick;*/
}

.masonry-brick {
  overflow: hidden;
  border-radius: 5px;
  margin: 0 0 8px 8px; 
  background-color: #333;
  color: white;
  position: relative;
}

.masonry-brick:after {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 5000;
  transform: translate(-50%, -50%);
  transition: font-size .25s, opacity .25s ease-in-out;
  font-weight: 700;
  opacity: .5;
  font-size: 1.25em;
}

.masonry-brick:hover:after {
  font-size: 2.25em;
  opacity: 1;
}



.masonry-img {
  object-fit: cover;
  width: 100%;
  max-width: 300px;
}
</style>  

我正在尝试制作如下图所示的东西,但我不知道如何制作。

我想要的风格

标签: cssimageflexboxgrid

解决方案


推荐阅读