gpt4 book ai didi

javascript - 如何使图像占据页面的一定百分比并相应地更改大小?

转载 作者:行者123 更新时间:2023-12-03 00:03:00 24 4
gpt4 key购买 nike

我正在尝试在一页上制作 9 个图像,每个图像占据宽度高度33%。请帮忙,我正在尝试制作一个电话界面。

@font-face {
font-family: font;
src: url("font.ttf") format("truetype");
}
body {
font-family:font;
}
img {
height:30vh;
}
.row {
width:100vw;
}
    <body>
<center>
<div class="row">
<a href="#"><img src="https://drive.google.com/uc?id=1hG6SSx5EVBlRwPz_MZ3m6W7Dt8XfbGOv" height="30"></a>
<a href="#"><img src="https://drive.google.com/uc?id=1hG6SSx5EVBlRwPz_MZ3m6W7Dt8XfbGOv" height="30"></a>
<a href="#"><img src="https://drive.google.com/uc?id=1hG6SSx5EVBlRwPz_MZ3m6W7Dt8XfbGOv" height="30"></a>
</div>
<div class="row">
<a href="#"><img src="https://drive.google.com/uc?id=1hG6SSx5EVBlRwPz_MZ3m6W7Dt8XfbGOv" height="30"></a>
<a href="#"><img src="https://drive.google.com/uc?id=1hG6SSx5EVBlRwPz_MZ3m6W7Dt8XfbGOv" height="30"></a>
<a href="#"><img src="https://drive.google.com/uc?id=1hG6SSx5EVBlRwPz_MZ3m6W7Dt8XfbGOv" height="30"></a>
</div>
<div class="row">
<a href="#"><img src="https://drive.google.com/uc?id=1hG6SSx5EVBlRwPz_MZ3m6W7Dt8XfbGOv" height="30"></a>
<a href="#"><img src="https://drive.google.com/uc?id=1hG6SSx5EVBlRwPz_MZ3m6W7Dt8XfbGOv" height="30"></a>
<a href="#"><img src="https://drive.google.com/uc?id=1hG6SSx5EVBlRwPz_MZ3m6W7Dt8XfbGOv" height="30"></a>
</div>
</body>

最佳答案

使用 CSS 网格创建 3x3 网格非常简单。
与图像相比,使用 widthmax-height

需要一些技巧

*{margin:0;box-sizing:border-box}html,body{min-height:100%;}

#images {
height: 100vh;
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(3, 1fr);
}

#images img{
display: block;
width: 100%;
max-height: 100%;
object-fit:cover;
}
<div id="images">

<a href="music.html"><img src="http://placehold.it/300x300/0bf/fff?text=1"></a>
<a href="music.html"><img src="http://placehold.it/300x300/f0b/fff?text=2"></a>
<a href="music.html"><img src="http://placehold.it/300x300/bf0/fff?text=3"></a>
<a href="music.html"><img src="http://placehold.it/300x300/fb0/fff?text=4"></a>
<a href="music.html"><img src="http://placehold.it/300x300/0fb/fff?text=5"></a>
<a href="music.html"><img src="http://placehold.it/300x300/b0f/fff?text=6"></a>
<a href="music.html"><img src="http://placehold.it/300x300/bbf/fff?text=7"></a>
<a href="music.html"><img src="http://placehold.it/300x300/bfb/fff?text=8"></a>
<a href="music.html"><img src="http://placehold.it/300x300/0bf/fff?text=9"></a>

</div>

关于javascript - 如何使图像占据页面的一定百分比并相应地更改大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55091572/

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