Answers for "align a div element to center"

CSS
-2

different ways to center a div

/* Centering an element without flexbox */
.parent-element {
  position: relative;
}

.child-element {
	position: absolute;
  	left: 50%;
  	top: 50%;
  	transform: translate(-50%, -50%);
}

/* Centering an element using flexbox */
.parent-element {
	display: flex;
  	align-items: center;
  	justify-content: center;
}
Posted by: Guest on June-30-2021
4

how to center a div element

/*ADD MARGIN auto to left and right*/
.box1{
    width:80%;
    margin:0 auto;
}
Posted by: Guest on August-27-2020
0

how to center a div

.MyDiv{
  	display: block;
  	margin-left: auto;
	margin-right: auto;
}
Posted by: Guest on August-31-2021

Browse Popular Code Answers by Language