我对这个html / css完全陌生,我试图用背景作为图像来浮动文本。是的,但是问题是文本浮动在图像的顶部。如果使用margin-top调整图像,这只是简单地下拉整个div。在此,我给出了我想要的图像表示。
html
<div class="maincon">
<div class="picon" style="background-image: linear-gradient(to bottom, rgba(0, 0, 0, .02), rgba(0, 0, 0, .8)), url('img/apple.jpg') "><p>Hi</p>
</div>
</div>
的CSS
.maincon {
margin-top: 95px;
width: 80%;
margin-left: auto;
margin-right: auto;
height: 100%;
}
.picon {
width: 100%;
height: 80%;
background: none center/cover #f2f2f2;
}
.picon p {
}
没有位置absolute
,您relative
可以使用flexbox
module.it支持所有最新的浏览器。
.element {
height: 80vh;
background: linear-gradient(to bottom, rgba(0, 0, 0, .02), rgba(0, 0, 0, .8)), url('http://cdn2.macworld.co.uk/cmsdata/features/3598128/iphone_6s_review_20.jpg');
background-size: cover;
align-items: flex-end;
display: flex;
}
p {
color: white;
font-size: 25px;
margin: 10px;
}
<div class="element">
<p>Apple iphone</p>
</div>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句