当我在iPhone上显示该页面时,我已经为ios设备创建了以下页面,每行底部都有多余的空白!我不知道如何删除每行之间的多余空白(每行有3张图像)以及如何使所有图像具有相同的大小(方形),如果您能帮助我,我将不胜感激。谢谢>
a {
text-decoration: none;
color: #003569
}
.images .line {
margin-bottom: 14vw;
margin-left: 2vw;
margin-right: 2vw;
display: flex
}
.images .line .img {
cursor: pointer;
position: relative;
text-align: center;
width: 47vw;
height: 47vw;
margin-right: 1vw
}
.images .line .img .img-wrap {
height: 100%;
overflow: hidden;
position: relative;
margin-bottom: 10px;
display: flex;
align-items: center;
background: #fff
}
.images .line .img .img-wrap:hover .desc {
transform: translateY(0)
}
.images .line .img img {
width: 100%;
position: absolute;
left: 0
}
.images .line .img .icon {
display: none
}
.images .line .img .download {
position: absolute;
bottom: -46px;
display: inline-block;
background: rgba(255, 255, 255, .7);
border-radius: 3px;
padding: 8px 10px;
color: #555;
left: 50%;
font-size: 14px;
transform: translateX(-50%);
box-shadow: .5px .5px 2px rgba(0, 0, 0, .1)
}
.images .line .img .video {
position: absolute;
top: 10px;
right: 10px;
width: 25px;
height: 25px;
background-image: url(./img/icon1.png);
background-size: cover;
z-index: 1000
}
.images .line .img .Carousel {
position: absolute;
top: 15px;
right: 20px;
width: 30px;
height: 30px;
background-image: url(./img/icon2.png);
#background-size: cover;
background-size: 65px 65px;
background-position: 0 0;
z-index: 1000
}
<div id="myDiv" class="images">
<div class="line">
<div class="img">
<a class="img-wrap" href="https://awebsite.com/n/a" target="_blank"><i class="icon"></i><img src="https://www.w3schools.com/howto/img_snow.jpg" alt=""></a>
<a class="download" href="https://" onclick="ma('a', 'b', 'c', 'd')" download="">Download</a></div>
<div class="img">
<a class="img-wrap" href="https://awebsite.com/n/b" target="_blank"><i class="icon"></i><img src="https://www.w3schools.com/howto/img_forest.jpg" alt=""><div class="video"></div></a>
<a class="download" href="https://" onclick="ma('a', 'b', 'c', 'd')" download="">Download</a></div>
<div class="img">
<a class="img-wrap" href="https://awebsite.com/n/c" target="_blank"><i class="icon"></i><img src="https://www.w3schools.com/howto/img_mountains.jpg" alt=""><div class="video"></div></a>
<a class="download" href="https://" onclick="ma('a', 'b', 'c', 'd')" download="">Download</a></div>
</div>
<div class="line">
<div class="img">
<a class="img-wrap" href="https://awebsite.com/n/d" target="_blank"><i class="icon"></i><img src="https://www.w3schools.com/w3images/rocks.jpg" alt=""><div class="Carousel"></div></a>
<a class="download" href="https://" onclick="ma('a', 'b', 'c', 'd')" download="">Download</a></div>
<div class="img">
<a class="img-wrap" href="https://awebsite.com/n/e" target="_blank">
<i class="icon"></i><img src="https://www.w3schools.com/w3images/falls2.jpg" alt="">
<div class="Carousel"></div>
</a>
<a class="download" href="https://" onclick="ma('a', 'b', 'c', 'd')" download="">Download</a></div>
<div class="img">
<a class="img-wrap" href="https://awebsite.com/n/f" target="_blank"><i class="icon"></i><img src="https://www.w3schools.com/w3images/paris.jpg" alt=""><div class="Carousel"></div></a>
<a class="download" href="https://" onclick="ma('a', 'b', 'c', 'd')" download="">Download</a>
</div>
</div>
</div>
答案 0 :(得分:1)
您可以使用flexbox进行行,填充顶部技巧来制作正方形,并使用对象适合度来使图像适合正方形(例如,如果您使用对象适合度,则需要使用polyfill-否则可以将图像替换为背景图片,如果您不想使用对象适合)
我已经离开了图标并下载了链接以供您样式
a {
text-decoration: none;
color: #003569
}
/* try not to over qualify selectors - it's inefficient and harder to maintain. if you have many line classes doing different things, then you need to use something more specific to this line - eg image-line */
.line {
margin: 2vw 0;
display: flex;
flex-direction: row;
justify-content: space-between;
/* spaces out images evenly with no space at the sides */
}
.img {
flex-basis: 32%; /* allow for 3 images per line with 2% space between each image */
max-width: 32%;
cursor: pointer;
}
.img-wrap {
display: block;
position: relative;
padding-top: 100%;
/* creates a square */
}
.img-wrap>img {
/* make img fill link */
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
object-fit: cover;
/* make image fill square and keep aspect ratio */
z-index: 1;
}
<div id="myDiv" class="images">
<!-- try indenting your code properly - helps with maintenance and just makes things easier to read and see where the nesting levels are -->
<div class="line">
<div class="img">
<a class="img-wrap" href="https://awebsite.com/n/a" target="_blank">
<i class="icon"></i>
<img src="https://www.w3schools.com/howto/img_snow.jpg" alt="">
</a>
<a class="download" href="https://" onclick="ma('a', 'b', 'c', 'd')" download="">Download</a>
</div>
<div class="img">
<a class="img-wrap" href="https://awebsite.com/n/b" target="_blank">
<i class="icon"></i>
<img src="https://www.w3schools.com/howto/img_forest.jpg" alt="">
<div class="video"></div>
</a>
<a class="download" href="https://" onclick="ma('a', 'b', 'c', 'd')" download="">Download</a>
</div>
<div class="img">
<a class="img-wrap" href="https://awebsite.com/n/c" target="_blank">
<i class="icon"></i>
<img src="https://www.w3schools.com/howto/img_mountains.jpg" alt="">
<div class="video"></div>
</a>
<a class="download" href="https://" onclick="ma('a', 'b', 'c', 'd')" download="">Download</a>
</div>
</div>
<div class="line">
<div class="img"><a class="img-wrap" href="https://awebsite.com/n/d" target="_blank"><i class="icon"></i><img src="https://www.w3schools.com/w3images/rocks.jpg" alt=""><div class="Carousel"></div></a><a class="download" href="https://" onclick="ma('a', 'b', 'c', 'd')"
download="">Download</a></div>
<div class="img"><a class="img-wrap" href="https://awebsite.com/n/e" target="_blank"><i class="icon"></i><img src="https://www.w3schools.com/w3images/falls2.jpg" alt=""><div class="Carousel"></div></a><a class="download" href="https://" onclick="ma('a', 'b', 'c', 'd')"
download="">Download</a></div>
<div class="img"><a class="img-wrap" href="https://awebsite.com/n/f" target="_blank"><i class="icon"></i><img src="https://www.w3schools.com/w3images/paris.jpg" alt=""><div class="Carousel"></div></a><a class="download" href="https://" onclick="ma('a', 'b', 'c', 'd')"
download="">Download</a></div>
</div>
</div>
有用链接:
答案 1 :(得分:0)
删除
margin-bottom: 14vw;
根据您的.images .line {} CSS规则
边距和填充导致空白。查看哪些CSS规则引起边距或填充的最简单方法是使用Chrome开发者工具
还要将所有图像的高度设置为47vh。将其更改为27vh。
.images .line .img {
width: 47vw;
height: 27vw;
}
答案 2 :(得分:0)
尝试改变此类的身高
.images .line .img {
cursor: pointer;
position: relative;
text-align: center;
width: 47vw;
height: 22vw;
margin-right: 1vw
}
a {
text-decoration: none;
color: #003569
}
.images .line {
margin-bottom: 14vw;
margin-left: 2vw;
margin-right: 2vw;
display: flex
}
.images .line .img {
cursor: pointer;
position: relative;
text-align: center;
width: 47vw;
height: 22vw;
margin-right: 1vw
}
.images .line .img .img-wrap {
height: 100%;
overflow: hidden;
position: relative;
margin-bottom: 10px;
display: flex;
align-items: center;
background: #fff
}
.images .line .img .img-wrap:hover .desc {
transform: translateY(0)
}
.images .line .img img {
width: 100%;
position: absolute;
left: 0
}
.images .line .img .icon {
display: none
}
.images .line .img .download {
position: absolute;
bottom: -46px;
display: inline-block;
background: rgba(255, 255, 255, .7);
border-radius: 3px;
padding: 8px 10px;
color: #555;
left: 50%;
font-size: 14px;
transform: translateX(-50%);
box-shadow: .5px .5px 2px rgba(0, 0, 0, .1)
}
.images .line .img .video {
position: absolute;
top: 10px;
right: 10px;
width: 25px;
height: 25px;
background-image: url(./img/icon1.png);
background-size: cover;
z-index: 1000
}
.images .line .img .Carousel {
position: absolute;
top: 15px;
right: 20px;
width: 30px;
height: 30px;
background-image: url(./img/icon2.png);
#background-size: cover;
background-size: 65px 65px;
background-position: 0 0;
z-index: 1000
}
<meta name="viewport" content="width=device-width, user-scalable=no">
<style>
</style>
</head>
<body>
<br><br>
<div id="myDiv" class="images">
<div class="line">
<div class="img"><a class="img-wrap" href="https://awebsite.com/n/a" target="_blank"><i class="icon"></i><img src="https://www.w3schools.com/howto/img_snow.jpg" alt=""></a> <a class="download" href="https://" onclick="ma('a', 'b', 'c', 'd')" download="">Download</a></div>
<div class="img"><a class="img-wrap" href="https://awebsite.com/n/b" target="_blank"><i class="icon"></i><img src="https://www.w3schools.com/howto/img_forest.jpg" alt=""><div class="video"></div></a><a class="download" href="https://" onclick="ma('a', 'b', 'c', 'd')" download="">Download</a></div>
<div class="img"><a class="img-wrap" href="https://awebsite.com/n/c" target="_blank"><i class="icon"></i><img src="https://www.w3schools.com/howto/img_mountains.jpg" alt=""><div class="video"></div></a><a class="download" href="https://" onclick="ma('a', 'b', 'c', 'd')" download="">Download</a></div>
</div>
<div class="line">
<div class="img"><a class="img-wrap" href="https://awebsite.com/n/d" target="_blank"><i class="icon"></i><img src="https://www.w3schools.com/w3images/rocks.jpg" alt=""><div class="Carousel"></div></a><a class="download" href="https://" onclick="ma('a', 'b', 'c', 'd')" download="">Download</a></div>
<div class="img"><a class="img-wrap" href="https://awebsite.com/n/e" target="_blank"><i class="icon"></i><img src="https://www.w3schools.com/w3images/falls2.jpg" alt=""><div class="Carousel"></div></a><a class="download" href="https://" onclick="ma('a', 'b', 'c', 'd')" download="">Download</a></div>
<div class="img"><a class="img-wrap" href="https://awebsite.com/n/f" target="_blank"><i class="icon"></i><img src="https://www.w3schools.com/w3images/paris.jpg" alt=""><div class="Carousel"></div></a><a class="download" href="https://" onclick="ma('a', 'b', 'c', 'd')" download="">Download</a></div>
</div>
</div>
</body>