Beniamino_Baggins Beniamino_Baggins - 3 months ago 9
CSS Question

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

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

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

It is working for me for most of my
<h2>
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

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.