You have incomplete CSS, as well as a couple errors both in your CSS and HTML. I put together a JSFiddle for you to view and use as a guide for correcting your problem and achieving what you need. My solution will take care of centering your inner div, as well as make that inner div display: table;
and the h1 display: table-cell
.
The reason for this is because you not only want to center your div text on the page, but you also want to center your text in your div (h1
) both horizontally and vertically. The only way to center your text properly vertically in it's parent container is to use display: table-cell;
along with vertical-align: middle;
You can view the JSFiddle here: https://jsfiddle.net/Lxpg4bxn/
Your HTML should be the following:
<div id="landingimg">
<div class="inner">
<h1>
Velkommen til hele Danmarks Fristad!
</h1>
<div class="clear"></div>
</div>
<div class="clear"></div>
</div>
And you should use the following CSS:
.clear {
clear: both;
}
#landingimg{
position: relative;
background: url("https://www.icr.org/i/wide/cat_walking_wide.jpg") no-repeat;
width: 960px;
max-width:100%;
height: 470px;
background-size: cover;
font-family: Arial, Helvetica, Sans-serif;
}
#landingimg div.inner {
position: absolute;
top: 50%;
left: 50%;
background-color: rgba(43, 44, 44, 0.5);
width: 400px;
height: 100px;
margin: -50px 0 0 -200px;
display: table;
}
#landingimg div.inner > h1{
padding: 0;
margin: 0;
text-align: center;
color: #fff;
font-weight: normal;
display: table-cell;
vertical-align: middle;
}