【发布时间】:2017-11-07 17:14:06
【问题描述】:
所以我有这个代码来显示图片库。我想在每个图像的中间放置“box-text”类。但是如果我想使用 position: relative 它不起作用。无论我如何在 css 中设置 top 属性,文本都不想高于图像的底部。
<div class="container">
<div class="box">
<img src="1.jpg" class="img-responsive">
<div class="box-text"><h2>Some text</h2><h3>other text</h3></div>
</div>
<div class="box">
<img src="2.jpg" class="img-responsive">
<div class="box-text"><h2>Some text</h2><h3>other text</h3></div>
</div>
<div class="box">
<img src="3.jpg" class="img-responsive">
<div class="box-text"><h2>Some text</h2><h3>other text</h3></div>
</div>
</div>
我的 CSS 样式:
.container{
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: center;
}
.box img{
z-index: 1;
}
.box-text{
position: relative;
top:50%;
left: 50%;
z-index: 2;
}
【问题讨论】:
标签: html css flexbox image-gallery