Centering div & text in css horizontal align

Are you trying to centre an element horizontally using css? Here are few methods to centre an element through css. It will help you to centre text and elements in div while developing a website.

 

Method 01. Centering an element

.content {
width:100px;
margin:0 auto;
}

 

Method 02. Centering an element

.content {
width:100px;
position:absolute;
left:0;
right:0;
margin-left:auto;
margin-right:auto;
}

 

Method 03. Centering text

 

TEXT – P&T IT BROTHER

 

.text {
text-align:center;
font-size:24px;
color:#ff3000;
}

 

Method 04. Centering an element with text

 

Text – P&T IT BROTHER

.container {
width:200px;
padding:20px 20px;
background:#333;
margin:0 auto;
}

.text {
color:#fff;
text-align:center;
}