Centering a Div In CSS

Status
This thread has been locked.
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

lAkjtzAZ0

Deactivated
Feedback score
16
Posts
1,071
Reactions
1,013
Resources
0
kinda depends on your HTML structure but you could use margins, the comment above^, or flexbox - all easy solutions
 

Guru Websites

A Specialist in Gaming Website Development
Supreme
Feedback score
18
Posts
225
Reactions
93
Resources
0
Add this to it,
display: block;
margin: auto;
 

Zelero

Deactivated
Feedback score
2
Posts
21
Reactions
7
Resources
0
It would really depend on your current code, but the code below should work if it is a block level element. A complete guide is available here, which makes it really easy to get it centred.
Code:
margin: 0 auto;
 

1017Ethan

Website Designer & Developer
Supreme
Feedback score
2
Posts
274
Reactions
246
Resources
0
Code:
<center>
Kappa

Jokes aside,

You can either create a center class.
Code:
.center {
  margin: 0 auto;
  display: block;
}

And then apply it to the div.
Code:
<div class="center"></div>

Or you apply the center to the div's class.
Code:
<div class="features">

.features {
  margin: 0 auto;
  display: block;
}

With Kind Regards,
Ethan S.
 

Xilcho

Web Designer
Supreme
Feedback score
0
Posts
109
Reactions
86
Resources
0
Figured I would mention it, since no one else has: if you want to center multiple divs that display:inline-block; text-align:center can be very useful. Since the divs are treated as text to their parent element, they will all be centered without having to use flex-box or other complicated methods. I apologize if that doesn't really make sense, and feel free to ask me any questions in order to clarify.
 
Status
This thread has been locked.
Top