Created
April 4, 2018 05:07
-
-
Save rahuls360/0f6dd830d3b491261c90034d6c71c952 to your computer and use it in GitHub Desktop.
Center within another div
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
<div id="outerDiv"> | |
<div class="other-divs"></div> | |
<div class="other-divs"></div> | |
<div class="div-to-be-centered"></div> | |
</div> | |
CSS | |
.div-to-be-centered{ | |
width: 300px; | |
position: absolute; | |
top: 50%; | |
left: 50%; | |
transform: translate(-50%,-50%); //use the exact center of div, instead of top-left corner | |
background: #fff; | |
padding: 10px; | |
z-index: 20; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment