简体   繁体   English

图像底部的浮动文本

[英]Floating text on bottom of image

I'm trying to create something like this: 我正在尝试创建类似这样的东西: 我正在尝试创造的 But I just can't get it right. 但是我只是做错了。 Here is what I have so far: jsfiddle . 到目前为止,这是我所拥有的: jsfiddle
HTML: HTML:

<div class="review">
    <div class="review-head">
        <h2> Batman Arkham Knight Review </h2>
    </div>
</div>

CSS: CSS:

.review-head {
    height: 20em;
    background: url(http://www.flickeringmyth.com/wp-content/uploads/2014/03/Arkham-Knight2.jpg) no-repeat center center;
    background-size: cover;
}
h2 {
    color: white;
    vertical-align: center;
}

What am I missing here? 我在这里想念什么?
If it matters or not, I'm trying to put the image inside a Bootstrap panel. 不管是否重要,我都试图将图像放入Bootstrap面板中。 Thanks for help! 感谢帮助!

Give your review-head element a position . 给您的review-head元素一个position This will allow you to position the h2 within it. 这将允许您在其中放置h2

 .review-head { height: 20em; background: url(http://www.flickeringmyth.com/wp-content/uploads/2014/03/Arkham-Knight2.jpg) no-repeat center center; background-size: cover; position: relative; } h2 { color: white; vertical-align: center; position: absolute; bottom: 20px; left: 20px; } 
 <div class="review"> <div class="review-head"> <h2> Batman Arkham Knight Review </h2> </div> </div> 

Change h2 to this: h2更改为此:

h2 {
    color: white;
    position:absolute;
    bottom: 0px;
}

My suggestion is to use a div element with id or class to achieve that. 我的建议是使用具有id或class的div元素来实现这一点。 Eg <div class="imgTextFooter" ></div> and apply here the style you want :) 例如<div class="imgTextFooter" ></div>并在此处应用您想要的样式:)

Forgot to add that you have to add position:relative to .review-head 忘记添加,您必须添加position:relative对于.review-head

fiddle 小提琴

Add

position: relative;

to the parent div. 到父级

Add

position: absolute; 
bottom: 0;

to the h2. 到h2。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM