center align a div code example

Example 1: position absolute center

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

Example 2: center a div in css

.container {
  display: flex;
  justify-content: center;
  align-items: center;
}

Example 3: css align center

//HTML
Hello World
//CSS .parent { display: flex; justify-content: center; align-items: center; }

Example 4: how to make a division center css

position:absolute;
top:50%;
left:50%;
transform:translate(-50%,-50%);

Example 5: how to center text in css

.class {
	text-align: center;
}

Example 6: how to center a div element

/*ADD MARGIN auto to left and right*/
.box1{
    width:80%;
    margin:0 auto;
}

Tags:

Misc Example