CSS Center Align
CSS Center Align
//to just center the text inside an element, use text-align: center;
.center {
text-align: center;
border: 3px solid green;
}
//to center an image, set left and right margin to auto and make it into a block element
img {
display: block;
margin-left: auto;
margin-right: auto;
width: 40%;
}
To horizontally center a block element (like <div>), use margin: auto;.
Center aligning has no effect if the width property is not set (or set to 100%).