Beniamino_Baggins Beniamino_Baggins - 1 year ago 102
CSS Question

<h2> not centering with margin auto because it is full width

I use class="m-x-auto" on my

tags which effectively sets margin-left and margin-right to auto.

It is working for me for most of my
tags but not for this one.

It is because in this example my seems to have full width (100%) and that means there is not space for a margin.

Photo of what it should be:

enter image description here

Photo of what it is:

enter image description here

How do I stop me from being full width so that it centers?

Answer Source

margin: auto just center the h2.
The issue here is the width: 100% by default because the tag h2 is display: block element.

So one solution is that you can set text-align: center.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download