Skip to content

Instantly share code, notes, and snippets.

@lqez
Created October 23, 2018 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lqez/dbd80864725e1daed25812a60b0e0d39 to your computer and use it in GitHub Desktop.
Save lqez/dbd80864725e1daed25812a60b0e0d39 to your computer and use it in GitHub Desktop.
Why we need margin-left for center-aligned text
<html>
<head>
<style>
body {
margin: 0;
}
h1 {
letter-spacing: 1em;
margin: 0;
}
div {
max-width: 400px;
margin: 1em auto;
text-align: center;
padding: 2em;
}
div.wrong {
background: red;
}
div.correct {
background: lime;
}
div.correct h1 {
margin-left: 1em;
}
</style>
</head>
<body>
<div class="wrong">
<h1>CENTER</h1>
</div>
<div class="correct">
<h1>CENTER</h1>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment