Saturday, January 23, 2021

How to center div using css

The most asked question about Div is "How to center div using CSS?"
Here You will get simplest form of div centering trick.

index.html

<div class="container">
	<div class="cbox">
		YOUR CONTENT HERE
	<div/>
<div/>

style.css

* {
  box-sizing: border-box;
  padding :0px;
  margin:0;
}

.container{
	display: flex;
	width: 100%;
	height: 100vh;
	background-color: purple;
	align-content: center;
	justify-content: center;
}
.cbox{
	width : 50%;
    height: 50%;
   	background-color: rgba(255, 255, 255, 0.521);
    margin: auto;
}
Output of above code.

You can learn more about display : flex here.

No comments:

Post a Comment

How to center div using css