在图片上加上文字的Div [英] Div with text over image
本文介绍了在图片上加上文字的Div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有包含图像和文字的列表.我想在图像上看到文字.
I have list with images and text. And I want to see text over image.
li{
float:right
}
.textoverlay {
margin: 50px 25px 0 0;
position: absolute;
z-index: 22;
}
<li>
<div class="textoverlay">
<a href=""><h1>Text</h1></a>
<p>Lorem ipsum dolor sit amet, co</p>
</div>
<img width="667" height="500" src="..." >
</li>
但是可以将<div class="textoverlay">
对准图像的中间吗?
But is it possible to align a <div class="textoverlay">
to the middle of the image?
推荐答案
以下css将使元素垂直居中对齐:
Following css will make an element vertically middle aligned:
.parent {
position: relative;
}
.child {
transform: translateY(-50%);
position: absolute;
top: 50%;
}
然后跟随css将使一个元素在水平和垂直方向上居中对齐:
And following css will make an element both horizontally and vertically middle aligned:
.parent {
position: relative;
}
.child {
transform: translateY(-50%);
position: absolute;
text-align: center;
right: 0;
top: 50%;
left: 0;
}
.list {
overflow: hidden;
list-style: none;
padding: 0;
margin: 0;
}
li{
position: relative;
float:right
}
.textoverlay {
transform: translateY(-50%);
text-align: center;
position: absolute;
z-index: 10;
right: 0;
top: 50%;
left: 0;
}
<ul class="list">
<li>
<div class="textoverlay">
<a href=""><h1>Text</h1></a>
<p>Lorem ipsum dolor sit amet, co</p>
</div>
<img width="350" height="150" src="http://placehold.it/350x150" >
</li>
</ul>
这篇关于在图片上加上文字的Div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文