See below some possibilities of how to do.
Option 1
Using a div
with an image in background
.
Demo
html,
body {
height: 100%;
min-height: 100%
}
.background {
background: url(http://www.hdwallpapers.in/walls/windows_xp_bliss-wide.jpg);
background-repeat: no-repeat;
background-size: cover;
width: 100%;
height: 100%;
}
.superior {
width: 40%;
height: 200px;
text-align: center;
background: #000;
font-size: 30px;
color: #fff;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
}
<div class="background">
<div class="superior">DIV</div>
</div>
Option 2
We put a div
to control the image. In the image we set its position as absolute
and the div
internal also, in that case there is no need to set the div
internal as absolute
in both cases will work.
Demo - Position: Absolute
.control {
position: relative;
width: 100%;
height: 500px;
overflow: hidden;
}
.control img {
position: absolute;
top: 0;
left: 0;
}
.superior {
width: 40%;
height: 200px;
text-align: center;
background: #000;
font-size: 30px;
color: #fff;
margin: auto;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
<div class="control">
<img src="http://www.hdwallpapers.in/walls/windows_xp_bliss-wide.jpg" alt="" />
<div class="superior">DIV</div>
</div>
Demo - Position: relative
.control {
position: relative;
width: 100%;
height: 500px;
}
.control img {
position: absolute;
top: 0;
left: 0;
}
.superior {
width: 40%;
text-align: center;
background: #000;
font-size: 30px;
color: #fff;
padding: 100px;
margin: 0 auto;
position: relative;
}
<div class="control">
<img src="http://www.hdwallpapers.in/walls/windows_xp_bliss-wide.jpg" alt="" />
<div class="superior">DIV</div>
</div>
A piece of advice is to use the first option, in such cases use background-size:cover
the image tends to behave better.
Can you explain better how you want the div to behave? Explain the context better. This is simple, but it can vary as you do depending on the use you want to give and whether the rest of the HTML is fixed or responsive. For example: http://jsfiddle.net/t0spre9g/
– Sergio
It is fixed, it would be in a layout like this: http://s8.postimg.org/7ee88htlh/image.jpg
– Thiago
Okay, serve the jsFiddle that I put in the Department above ^ ?
– Sergio
Yes, he was on top, but the div was on the left coming out of the block, there is some way to put it on the right without having to put gigantic values on the top/left?
– Thiago