Reputation: 120
How can you overlay text over an image with a background, like this
<div id="slider" class="nivoSlider">
<img src="images/slide1.jpg"/>
</div>
Upvotes: 1
Views: 3998
Reputation: 599
You mean something like this demo ?
Important things:
The parent div has to have position: relative
and the text div position: absolute
. Then you position it on the image with top: ?; left: ?; bottom: ?
and text-align: center
.
Here is the HTML:
<div id="slider">
<img src="http://www.primolo.de/archiv/BrAlIbKe/hp_bilder/luftballons2_v-gallery_1_.jpg"/>
<div id="slider-text">This is awesome</div>
</div>
And the CSS:
#slider {
position: relative;
width: 400px;
}
#slider-text {
position: absolute;
width: 200px;
color: #FFF;
font-weight: bold;
bottom: 5%;
left: 30px;
padding: 30px 0;
text-align: center;
background-color: rgba(200, 50, 0, 0.8);
}
Most of the stuff was not necessary, but I think it looks pretty nice.
Hope this helps.
Upvotes: 1
Reputation: 3124
Like this http://codepen.io/anon/pen/jaBho
<div>
<h4>Lorem ipsum dolor sit amet, consectetur adipisicing elit. In, placeat!</h4>
<img src="http://rack.0.mshcdn.com/media/ZgkyMDE0LzA4LzI0LzVkL21pbGV5ZG9nLmEzMDVjLmpwZwpwCXRodW1iCTk1MHg1MzQjCmUJanBn/1750ef37/ade/miley-dog.jpg">
</div>
div{position: relative;
margin: 35px;
width: 500px;
height: 300px;
overflow: hidden;
}
h4{
background-color: rgba(174, 0, 0, 0.51);
position: absolute;
bottom: 30px;
left: 30px;
width: 300px;
padding: 20px;
display: block;
color: white;
font-size: 24px;
}
Upvotes: 2