[英]Image gallery in html. How to make images appear the same size?
How to make images from image gallery appear same size? 如何使图像库中的图像看起来相同大小? (if originally they have different dimensions). (如果它们最初具有不同的尺寸)。
Add a description of the image here 在此处添加图片说明 <div class="img"> <a target="_blank" href="https://unsplash.it/g/300/400"> <img src="https://unsplash.it/g/200/300" alt="Forest" width="600" height="400"> </a> <div class="desc">Add a description of the image here</div> </div> <div class="img"> <a target="_blank" href="https://unsplash.it/g/400/400"> <img src="https://unsplash.it/g/400/400" alt="Northern Lights" width="600"height="400"> </a> <div class="desc">Add a description of the image here</div> </div> <div class="img"> <a target="_blank" href="https://unsplash.it/g/400/400"> <img src="https://unsplash.it/g/400/400" alt="Northern Lights" width="600" height="400"> </a> <div class="desc">Add a description of the image here</div> </div> <div class="img"> <a target="_blank" href="https://unsplash.it/g/400/400"> <img src="https://unsplash.it/g/400/400" alt="Northern Lights" width="600" height="400"> </a> <div class="desc">Add a description of the image here</div>
Update Css Add img
Class In Css. 更新CSS在CSS中添加img
类。 And Remove height :auto
in div.img img
Class 并删除height :auto
div.img img
类中的height :auto
Note: You Can Change Hight & width in Css 注意:您可以更改CSS的高度和宽度
img
{
width:300px;
height:200px;
}
div.img img
{
width: 100%;
}
Snippet Example Below 下面的代码段示例
div.img { margin: 5px; border: 1px solid #ccc; float: left; width: 180px; } div.img:hover { border: 1px solid #777; } div.img img { width: 100%; } div.desc { padding: 15px; text-align: center; } img { width:300px; height:200px; }
<!DOCTYPE html> <body> <div class="img"> <a target="_blank" href="https://unsplash.it/200/300/?random"> <img src="https://unsplash.it/200/300/?random" alt="Trolltunga Norway" > </a> <div class="desc">Add a description of the image here</div> </div> <div class="img"> <a target="_blank" href="https://unsplash.it/g/300/400"> <img src="https://unsplash.it/g/200/300" alt="Forest" > </a> <div class="desc">Add a description of the image here</div> </div> <div class="img"> <a target="_blank" href="https://unsplash.it/g/400/400"> <img src="https://unsplash.it/g/400/400" alt="Northern Lights" > </a> <div class="desc">Add a description of the image here</div> </div> <div class="img"> <a target="_blank" href="https://unsplash.it/g/400/400"> <img src="https://unsplash.it/g/400/400" alt="Northern Lights" > </a> <div class="desc">Add a description of the image here</div> </div> <div class="img"> <a target="_blank" href="https://unsplash.it/g/400/400"> <img src="https://unsplash.it/g/400/400" alt="Northern Lights" > </a> <div class="desc">Add a description of the image here</div> </div> <div class="img"> <a target="_blank" href="https://unsplash.it/g/400/400"> <img src="https://unsplash.it/g/400/400" alt="Northern Lights" > </a> <div class="desc">Add a description of the image here</div> </div> <div class="img"> <a target="_blank" href="https://unsplash.it/g/400/400"> <img src="https://unsplash.it/g/400/400" alt="Northern Lights" > </a> <div class="desc">Add a description of the image here</div> </div>
That depends on how you want to adjust the ones that aren't the same size. 这取决于您要如何调整大小不同的那些。 In other words, if you have a 300x200 image and a 300x300 image, you could: 换句话说,如果您有300x200的图片和300x300的图片,则可以:
These are all options you have and they'd all be implemented a little differently, so first figure out which way you want to go. 这些都是您所拥有的选项,并且它们的实现方式都将有所不同,因此首先要弄清楚您想采用哪种方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.