Beniamino_Baggins Beniamino_Baggins - 7 months ago 32
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?


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.