首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >图片库HTML CSS

图片库HTML CSS
EN

Stack Overflow用户
提问于 2020-05-27 19:07:27
回答 3查看 86关注 0票数 0

我在我的画廊中遇到了图像大小的问题,我已经阅读了多个线程和yt视频,但似乎不能自己弄清楚

问题的图像:

代码语言:javascript
复制
* {
  box-sizing: border-box;
}

.gallery {
  border: 1px solid #ccc;
}

.gallery img {
  width: 100%;
  height: auto;
}

.des {
  padding: 15px;
  text-align: center;
}

.responsive {
  padding: 0 6px;
  float: left;
  width: 25%;
}
代码语言:javascript
复制
<h1>Veckans deals!</h1>
<div class="responsive">
  <div class="gallery">
    <a href="vdeals_ett.jpg" target="_blank"><img src="https://topracingdrone.com/wp-content/uploads/2018/12/DJI-Phantom-4-Photogrammetry-Drone-300x184.png" alt="Drönare" width="300" height="200"></a>
    <div class="des">Add a desciption of the picture</div>
  </div>
</div>


<div class="responsive">
  <div class="gallery">
    <a href="vbild_two.jpg" target="_blank"><img src="https://topracingdrone.com/wp-content/uploads/2018/12/Holy-Stone-HS100-UAV-photography-drone-300x176.png" alt="Drönare" width="300" height="200"></a>
    <div class="des">Add a desciption of the picture</div>
  </div>
</div>


<div class="responsive">
  <div class="gallery">
    <a href="vbild_tre.jpg" target="_blank"><img src="https://topracingdrone.com/wp-content/uploads/2018/12/Parrot-Bebop-2-drone-300x143.jpeg" alt="Drönare" width="300" height="200"></a>
    <div class="des">Add a desciption of the picture</div>
  </div>
</div>


<div class="responsive">
  <div class="gallery">
    <a href="vbild_fyra.jpg" target="_blank"><img src="https://topracingdrone.com/wp-content/uploads/2018/12/GoPro-Hero-4-Silver-300x300.jpg" alt="Landskap" width="300" height="200"></a>
    <div class="des">Add a desciption of the picture</div>
  </div>
</div>

EN

回答 3

Stack Overflow用户

发布于 2020-05-27 19:23:04

如果不为所有图像设置固定的高度,您就无法在使用float的同时使它们全部拉伸。您有三个选择。

  1. 在图像上设置一个固定的高度,并使用object-fit: cover让它看起来像是在拉伸,而实际上它是覆盖它的,并在图像上使用
  2. flex-grow: 1 (see this example,flexbox使所有图像具有相同的宽度和高度,如果它们可以被统一。
票数 1
EN

Stack Overflow用户

发布于 2020-05-27 19:19:26

我确信这些图像具有不同的分辨率。前两张图像具有相同的分辨率,例如3:2。后两张图像具有相同的分辨率,例如2:1,但与前两张图像不同。请尝试修复所有图像的分辨率。

票数 0
EN

Stack Overflow用户

发布于 2020-05-27 19:19:59

您的图像的高度/宽度不同,就像我为您制作代码片段时发现的图像一样。因此确定哪个方向是重要的,并使用vh/vw和auto

More here

代码语言:javascript
复制
* {
  box-sizing: border-box;
}

.gallery {
  border: 1px solid #ccc;
}

.gallery img {
  width: auto;
  height: 15vh;
}

.des {
  padding: 15px;
  text-align: center;
}

.responsive {
  padding: 0 6px;
  float: left;
  width: 25%;
}
代码语言:javascript
复制
<h1>Veckans deals!</h1>
<div class="responsive">
  <div class="gallery">
    <a href="vdeals_ett.jpg" target="_blank"><img src="https://topracingdrone.com/wp-content/uploads/2018/12/DJI-Phantom-4-Photogrammetry-Drone-300x184.png" alt="Drönare" width="300" height="200"></a>
    <div class="des">Add a desciption of the picture</div>
  </div>
</div>


<div class="responsive">
  <div class="gallery">
    <a href="vbild_two.jpg" target="_blank"><img src="https://topracingdrone.com/wp-content/uploads/2018/12/Holy-Stone-HS100-UAV-photography-drone-300x176.png" alt="Drönare" width="300" height="200"></a>
    <div class="des">Add a desciption of the picture</div>
  </div>
</div>


<div class="responsive">
  <div class="gallery">
    <a href="vbild_tre.jpg" target="_blank"><img src="https://topracingdrone.com/wp-content/uploads/2018/12/Parrot-Bebop-2-drone-300x143.jpeg" alt="Drönare" width="300" height="200"></a>
    <div class="des">Add a desciption of the picture</div>
  </div>
</div>


<div class="responsive">
  <div class="gallery">
    <a href="vbild_fyra.jpg" target="_blank"><img src="https://topracingdrone.com/wp-content/uploads/2018/12/GoPro-Hero-4-Silver-300x300.jpg" alt="Landskap" width="300" height="200"></a>
    <div class="des">Add a desciption of the picture</div>
  </div>
</div>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62041631

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档