我正在尝试在测试网站上创建图库部分,我已经制作了图库但由于某种原因,标签根本不会填充图像的高度和宽度,它们似乎都崩溃到了第一个第一行图像的四分之一。
以下是代码:(实际上,使用此代码,a标签占据了高度和宽度,但图像堆叠在彼此之上)
HTML
<section class="portfolio">
<h1>— PORTFOLIO —</h1>
<div class="gallery">
<a href="#">
<img src="img/img1.jpg" alt="">
</a>
</div>
<div class="gallery">
<a href="#">
<img src="img/img2.jpg" alt="">
</a>
</div>
<div class="gallery">
<a href="#">
<img src="img/img3.jpg" alt="">
</a>
</div>
<div class="gallery">
<a href="#">
<img src="img/img4.jpg" alt="">
</a>
</div>
<div class="gallery">
<a href="#">
<img src="img/img5.jpg" alt="">
</a>
</div>
<div class="gallery">
<a href="#">
<img src="img/img6.jpg" alt="">
</a>
</div>
<div class="gallery">
<a href="#">
<img src="img/img7.jpg" alt="">
</a>
</div>
<div class="gallery">
<a href="#">
<img src="img/img8.jpg" alt="">
</a>
</div>
<div class="gallery">
<a href="#">
<img src="img/img9.jpg" alt="">
</a>
</div>
<div class="gallery">
<a href=#"">
<img src="img/img10.jpg" alt="">
</a>
</div>
<div class="gallery">
<a href="#">
<img src="img/img11.jpg" alt="">
</a>
</div>
<div class="gallery">
<a href="#">
<img src="img/img12.jpg" alt="">
</a>
</div>
</section>
CSS
.portfolio {
width: 90%;
position: relative;
left: 80px;
}
.portfolio h1 {
text-align: center;
margin-bottom: 50px;
margin-top: 50px;
font-size: 60px;
font-family:'Poiret One', cursive;
}
.gallery img {
margin: 5px;
float: left;
height: 230px;
width: 330px;
border: 1px solid #000;
border-radius: 3px;
}
.gallery a {
display: inline-block;
}
我可能做了一些可怕的错误,但我无法解决这个问题!
提前致谢。
答案 0 :(得分:1)
您可以尝试这样做。
删除float:left
上的.gallery img
。然后在display:inline-block
和.gallery img
.gallery
.portfolio {
width: 90%;
position: relative;
left: 80px;
}
.portfolio h1 {
text-align: center;
margin-bottom: 50px;
margin-top: 50px;
font-size: 60px;
}
.gallery{
display:inline-block;
}
.gallery img {
display:inline-block;
margin: 5px;
height: 230px;
width: 330px;
border: 1px solid #000;
border-radius: 3px;
}
.gallery a {
display: inline-block;
}
<section class="portfolio">
<h1>— PORTFOLIO —</h1>
<div class="gallery">
<a href="#">
<img src="img/img1.jpg" alt="">
</a>
</div>
<div class="gallery">
<a href="#">
<img src="img/img2.jpg" alt="">
</a>
</div>
<div class="gallery">
<a href="#">
<img src="img/img3.jpg" alt="">
</a>
</div>
<div class="gallery">
<a href="#">
<img src="img/img4.jpg" alt="">
</a>
</div>
<div class="gallery">
<a href="#">
<img src="img/img5.jpg" alt="">
</a>
</div>
<div class="gallery">
<a href="#">
<img src="img/img6.jpg" alt="">
</a>
</div>
<div class="gallery">
<a href="#">
<img src="img/img7.jpg" alt="">
</a>
</div>
<div class="gallery">
<a href="#">
<img src="img/img8.jpg" alt="">
</a>
</div>
<div class="gallery">
<a href="#">
<img src="img/img9.jpg" alt="">
</a>
</div>
<div class="gallery">
<a href=#"">
<img src="img/img10.jpg" alt="">
</a>
</div>
<div class="gallery">
<a href="#">
<img src="img/img11.jpg" alt="">
</a>
</div>
<div class="gallery">
<a href="#">
<img src="img/img12.jpg" alt="">
</a>
</div>
</section>
希望这有帮助。
答案 1 :(得分:0)