See some possibilities below for how to do it.
Option 1
Using 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 div
internal also, in this 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>
One advice is to use the first option, in these cases use background-size:cover
the image tends to behave better.