centering text vertically in the middle of the page

I would like to center the text on my homepage vertical in the middel of the page. Right now i tried to do this with a percentage, but this isn't the right way because when i open the webpage on my phone or an ipad the text doesn't center. Does anyone know how i can center it the right way?

@charset "UTF-8";
/* CSS Document */

body {
	background: white;
}

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

/* wrapper */
#wrapper {
	min-height: 100%;
	position: relative;
}

/* menu */
#header {
    height: 80px;
	width: 100%;
    background: #000000;
}

li {
	display: block;
    float: left;
	margin-left: 10px;
	margin-top: 20px;
	margin-right: 10px;
}

a {
	position: reletive;
	text-decoration: none;
	color: #ffffff;
	font-size: 24px;
	font-family: 'Open Sans Condensed';
}

li:hover{
	border-bottom: 1px solid white;
	padding-bottom: 0px;
}
	
.home {
	margin-left: 30px;
}

.contact {
	float: right;
	margin-right: 30px;
}

/*content*/
#content {
	padding-bottom:80px;
}

/* homepage */
.anouk {
	font-family: 'Oswald';
	color: #000000;
	font-size: 80px;
	text-align: center;	
	margin-top: 15%;
}


/* footer */
#footer {
	background: #000000;
	width: 100%;
	height: 80px;
	position: absolute;
	bottom: 0;
	left: 0;
	text-align: center;
}

.icoontjes {
	margin-top: 15px;
	margin-left: 10px;
	margin-right: 10px;
	height: 50px;
}

.icoontjes:hover {
    opacity: 0.8;
}
<!doctype html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Anouk</title>
    <link rel="stylesheet" type="text/css" href="stylesheet.css">
    <link href="https://fonts.googleapis.com/css?family=Oswald|Open+Sans+Condensed:300" rel="stylesheet" type="text/css"> 
  </head>
  <body>
    <div id="wrapper">
      <div id="header">
        <div class="menu">
          <!--Home-->
          <li class="home">
            <a href="index.html">
            Home
            </a>
          </li>
          <!--Over Mij-->
          <li class="over">
            <a href="over.html">
            Over Mij
            </a>
          </li>
          <!--Portfolio-->
          <li class="portfolio">
            <a href="portfolio.html">
            Portfolio
            </a>
          </li>
          <!--Contact-->
          <li class="contact">
            <a href="contact.html">
            Contact
            </a>
          </li>                    
        </div>
      </div>
      <div id="content"> 
        <p class="anouk">
        Anouk Den Haag
        </p>
      </div>
      <div id="footer">
        <a href="mailto:#">
          <img class="icoontjes" src="icoontjes/email.png" alt="email">
        </a>
        <a href="#" target="_blank">
          <img class="#" src="icoontjes/facebook.png" alt="facebook">
        </a>
        <a href="#" target="_blank">
        <img class="icoontjes" src="icoontjes/instagram.png" alt="instagram">
        </a>
      </div>
    </div>        
  </body>
</html>

Answers


display offers you 2 options : the table layout or the flex model ( both will push footer down if content grows)


test snippets in full page mode and resize window


1) display:table/table-row/table-cell (should include IE8 and older browsers CSS 2.1)

@charset "UTF-8";

/* CSS Document */

body {
  background: white;
}

html,
body,
#wrapper {
  width: 100%;
  margin: 0;
  padding: 0;
  height: 100%;
}


/* wrapper */

#wrapper {
  display: table;
  position: relative;
}


/* menu */

#header {
  height: 80px;
  display: table-row;
  background: #000000;
}

li {
  display: block;
  float: left;
  margin-left: 10px;
  margin-top: 20px;
  margin-right: 10px;
}

a {
  position: reletive;
  text-decoration: none;
  color: #ffffff;
  font-size: 24px;
  font-family: 'Open Sans Condensed';
}

li:hover {
  border-bottom: 1px solid white;
  padding-bottom: 0px;
}

.home {
  margin-left: 30px;
}

.contact {
  float: right;
  margin-right: 30px;
}


/*content*/

#content {
  vertical-align: middle;
  display: table-cell;
}


/* homepage */

.anouk {
  font-family: 'Oswald';
  color: #000000;
  font-size: 80px;
  text-align: center;
}


/* footer */

#footer {
  background: #000000;
  width: 100%;
  height: 80px;
  display: table-row;
  text-align: center;
}

.icoontjes {
  margin-top: 15px;
  margin-left: 10px;
  margin-right: 10px;
  height: 50px;
}

.icoontjes:hover {
  opacity: 0.8;
}
<!doctype html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Anouk</title>
    <link rel="stylesheet" type="text/css" href="stylesheet.css">
    <link href="https://fonts.googleapis.com/css?family=Oswald|Open+Sans+Condensed:300" rel="stylesheet" type="text/css"> 
  </head>
  <body>
    <div id="wrapper">
      <div id="header">
        <div class="menu">
          <!--Home-->
          <li class="home">
            <a href="index.html">
            Home
            </a>
          </li>
          <!--Over Mij-->
          <li class="over">
            <a href="over.html">
            Over Mij
            </a>
          </li>
          <!--Portfolio-->
          <li class="portfolio">
            <a href="portfolio.html">
            Portfolio
            </a>
          </li>
          <!--Contact-->
          <li class="contact">
            <a href="contact.html">
            Contact
            </a>
          </li>                    
        </div>
      </div>
      <div id="content"> 
        <p class="anouk">
        Anouk Den Haag
        </p>
      </div>
      <div id="footer">
        <a href="mailto:#">
          <img class="icoontjes" src="icoontjes/email.png" alt="email">
        </a>
        <a href="#" target="_blank">
          <img class="#" src="icoontjes/facebook.png" alt="facebook">
        </a>
        <a href="#" target="_blank">
        <img class="icoontjes" src="icoontjes/instagram.png" alt="instagram">
        </a>
      </div>
    </div>        
  </body>
</html>

Try adding this CSS to the text you want centered:

.your_centered_element {
    position: absolute;
    top:50%;
    left: 50%;
    transform: translateX(-50%) translateY(-50%);
}

This will keep the element centered.

Read about the transform: translateX(-50%) translateY(-50%); in the MDN docs

Hope this helps!


One solution here is to use viewport-width and viewport-height units:

.anouk {
position: absolute;
top: 0;
left: 0;
width: 100vw;
line-height: 100vh;
margin: 0;
padding: 0;
text-align: center;
}

for centering the text you have to use **margin auto**
css file--

* {
    border: 1px dashed black;
}

div >p {
    height: 50px;
    width: 100px;
    border: 2px solid black;
    border-radius: 5px;
    background-color: #FFD700;
    margin: auto;
}

  html code 
  <!DOCTYPE html>
<html>
    <head>
        <link type="text/css" rel="stylesheet" href="stylesheet3.css"/>
        <title>Result</title>
    </head>
    <body>
        <div><p >
        Anouk Den Haag
        </p></div>
    </body>
</html>

SEE THE SNAPSHOT


Need Your Help

Edit Validation.ErrorTemplate in code

wpf validation user-controls

I have a UserControl that contains a TextBox. The TextBox.Text property is data-bound and validated. When a Validation.Error occurs, I would like to edit the Validation.ErrorTemplate. Specifically...

Synchronizing databases between a local and remote development environment

php mysql sql data-migration

I've being working on a local project recently, and have been synchronising it with an online server.