Skip to content
Recommend our themes and earn 30% of our share of every sale you bring. Free to join.Earn by recommending our themes Become an affiliate

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.