Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I know there are various solutions posted for this issue here, but for the life of me I can't get any of them to work.

For a responsive website I'm trying to center an h1 text in a div.

Centering horizontally is not an issue, but I'm having problems getting it centered vertically. Probably I'm doing something wrong or misunderstanding the explanations I found here (and in all probability both).

So as I'm probably interpreting earlier solutions given the wrong way, could someone please explain what exactly I have to add to the code beneath to get the h1 to center vertically?

(As you can see, I've already stripped the code of all my previous attempts to do so myself)

My CSS:

html, body {
height: 100%;
margin: 0;
}

#section1 {
min-height: 90%; 
text-align:center
}

My HTML:

<div class="section" id="section1" style="background-image:url('example.jpg');">
<h1>Lorem ipsum</h1>
</div> 
share|improve this question
    
Unfortunately questions related to programming are off-topic for this site. You might ask this question over at Stack Overflow, but be sure to search the answers there first. Please feel free to ask other questions that fall under this site's guidelines in the future though. –  dan Dec 13 '13 at 6:38
    
Ah, sorry. Assumed that HTML and CSS would be Webmaster related. Should have read the help center more carefully. Reposted the question at Stack Overflow. –  Edward Touw Dec 13 '13 at 9:19
1  
Question asked and answered here: stackoverflow.com/questions/20562860/… So what's best to do now? Should I remove the question from here as it's posted in the wrong forum? Of leave it for future reference? –  Edward Touw Dec 13 '13 at 10:01
    
Thanks for the update, glad you got an answer to your question. Either is fine - you can delete it, or leave it here so that others on this site can see the link and answer there. –  dan Dec 13 '13 at 13:41
add comment

closed as off-topic by dan Dec 13 '13 at 6:38

  • This question does not appear to be about webmastering within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.