我正在制作画廊,但图像放大得太近了,我希望图像适合!
我尝试了一些宽度和高度调整,但它看起来不对
HTML 代码。
<div class="bod">
<h1 class="header1">Gallery</h1>
<div class="wrapper-gallery">
<div class="media">
<div class="layer">
<p class="para">Student: RANDOM</p>
</div>
<img src="https://images.unsplash.com/photo-1431818563807-927945852ab6?dpr=1&auto=format&fit=crop&w=1199&h=899&q=80&cs=tinysrgb&crop=" alt="" />
</div>
<div class="media">
<div class="layer">
<p class="para">Student: RANDOM</p>
</div>
<img src="https://images.unsplash.com/photo-1431818563807-927945852ab6?dpr=1&auto=format&fit=crop&w=1199&h=899&q=80&cs=tinysrgb&crop=" alt="" />
</div>
<div class="media">
<div class="layer">
<p class="para">Student: RANDOM</p>
</div>
<img src="https://images.unsplash.com/photo-1431818563807-927945852ab6?dpr=1&auto=format&fit=crop&w=1199&h=899&q=80&cs=tinysrgb&crop=" alt=""/>
</div>
</div>
</div>
</div>
上面的CSS!
<style>
@import url('https://fonts.googleapis.com/css?family=Inconsolata|Source+Sans+Pro:200,300,400,600');
.bod {
height: 100vh;
display: flex;
width: 100%;
flex-direction: column;
justify-content: center;
align-items: center;
background: #E0E0E0;
overflow: hidden;
}
.header1 {
font-family: 'Source Sans Pro', sans-serif;
font-size: 22px;
color: #151E3F;
font-weight: 300;
letter-spacing: 2px;
}
.wrapper-gallery {
display: flex;
justify-content: center;
align-items: center;
> * {
margin: 5px;
}
}
.media {
width: 300px;
height: 200px;
overflow: hidden;
position: relative;
display: flex;
justify-content: center;
align-items: center;
img {
max-width: 100%;
height: auto;
}
}
.layer {
opacity: 0;
position: absolute;
display: flex;
justify-content: center;
align-items: center;
width: 10px;
height: 90%;
background: #FFF;
color: #151E3F;
transition: all 0.9s ease;
p {
transition: all 0.9s ease;
transform: scale(0.2)
}
}
.para {
font-family: 'Inconsolata', monospace;
text-align: center;
font-size: 15px;
letter-spacing:1px;
font-size: 15px;
}
.media:hover .layer {
opacity: 0.8;
width: 95%;
transition: all 0.5s ease;
p {
transform: scale(1);
transition: all 0.9s ease;
}
}
@media (max-width: 800px){
.bod {
transform: scale(0.8);
}
}
@media (max-width: 600px) {
.wrapper-gallery {
display: block;
> * {
margin: 10px;
}
}
}
</style>
没有错误,它只是放大得非常近,我无法让它适应!有没有办法让图像紧贴?
最佳答案
@azametzin,img 没有嵌套在 layer 中。
错误出在 .media 的 CSS 中。它无效,至少在 Chrome 中无效。
它应该是这样的:
.media {
width: 300px;
height: 200px;
overflow: hidden;
position: relative;
display: flex;
justify-content: center;
align-items: center;
}
.media img {
max-width: 100%;
height: auto;
}
关于html - 如何使图像缩小到正常 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57262511/