gpt4 book ai didi

css - html 格式的图片库。如何使图像显示为相同大小?

转载 作者:太空宇宙 更新时间:2023-11-04 09:38:56 24 4
gpt4 key购买 nike

如何使图片库中的图片显示为相同大小? (如果它们最初具有不同的尺寸)。

jsfiddle.net

在此处添加图片说明
<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>

最佳答案

更新 Css 在 Css 中添加 img 类。并删除 div.img img 类中的 height :auto

注意:您可以在 Css 中更改高度和宽度

img
{
width:300px;
height:200px;
}
div.img img
{
width: 100%;
}

查看现场演示 Here

下面的代码片段示例

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>

关于css - html 格式的图片库。如何使图像显示为相同大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40099208/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com