Is it possible to center an inline element horizontally without additional markup or styling of parent containers?

The question is basically already indicated in the title, but for clarification: I'm trying to horizontally center the <a> anchor in the main content area.

I would like to do this without:

  • Using fixed width
  • Adding additional markup (e.g. extra div parent)
  • Styling a parent container (e.g. setting a parent in text-align:center )
  • Setting <a> as a full-width block (I would like the area from the click to be as large as the link itself)

So basically, I would like to do this simply by using the anchor style in css, in a dynamic (shrinkwrap) path. I tried, but have not yet found a way, does anyone know how to do this?

+8
html css inline centering
source share
1 answer

Try this: DEMO

 a { display: table; margin: auto; } 
+20
source share

All Articles