Skip to content

Instantly share code, notes, and snippets.

@rahuls360
Created April 4, 2018 05:07
Show Gist options
  • Save rahuls360/0f6dd830d3b491261c90034d6c71c952 to your computer and use it in GitHub Desktop.
Save rahuls360/0f6dd830d3b491261c90034d6c71c952 to your computer and use it in GitHub Desktop.
Center within another div
<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