Skip to content

Instantly share code, notes, and snippets.

@mateuszkocz
Created April 6, 2012 16:34
Show Gist options
  • Save mateuszkocz/2321182 to your computer and use it in GitHub Desktop.
Save mateuszkocz/2321182 to your computer and use it in GitHub Desktop.
Centring some element
.wrap {
/* Unimportant styling. */
background-color: #ffa500;
width: 400px;
height: 200px;
/* Solution (part I)*/
/* This code allows element inside the .wrap to be positioned in the middle. */
display: table-cell;
vertical-align: middle;
}
.centre {
/* Another unimportant styling. */
width: 200px;
background-color: #424242;
color: #fff;
text-align: center;
/* Solution (part II) */
/* Now we have a vertical centring. */
margin: 0 auto;
}
<div class="wrap">
<div class="centre">I'm the centre of the universe!</div>
</div>
{"view":"split-vertical","seethrough":"","prefixfree":"1","page":"css"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment