Skip to content

Center div inside another div horizontally

Updated 04 Jun 2018
You need to use margin: 0 auto; for inner div. It will automatically center align inner div according to the width of outer div.

Source code

<style>
	.outer-div {
		background-color: rgba(0, 0, 0, 0.5);
		padding: 50px 0;
		width: 100%;
	}
	.inner-div {
		background-color: #fff;
		width: 200px;
		height: 300px;
		margin: 0 auto;
	}
</style>

<div class="outer-div">
	<div class="inner-div"></div>
</div>

See it live

More code answers

Comments

Log in to leave a comment.