Created
May 13, 2018 14:20
-
-
Save Deityhub/eab9bb880e12284f388618d3ef2c60eb to your computer and use it in GitHub Desktop.
How to center a text in the middle of it's containing parent. No matter how one adjust the height or width of the container, it still remains in the middle.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width initial-scale=1.0"> | |
/*Link the css file here to see how this code works*/ | |
<link rel="stylesheet" href="style.css" > | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<div class="container"> | |
<section class="container__left"> | |
<p> | |
left section | |
</p> | |
</section> | |
<section class="container__right"> | |
<p> | |
right section | |
</p> | |
</section> | |
</div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.container { | |
width: 80%; | |
margin: auto; | |
color: yellow; | |
} | |
.container__left { | |
width: 50%; | |
float: left; | |
background: rgb(90, 90, 90); | |
} | |
.container__right { | |
width: 50%; | |
float: right; | |
background: rgb(200, 200, 200); | |
} | |
.container__left, | |
.container__right { | |
height: 500px; | |
display: table; | |
text-align: center; | |
} | |
p { | |
display: table-cell; | |
vertical-align: middle; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
initial code snippet to show how this works.