How can I center align a div without knowing the width?

后端 未结 9 1505
感情败类
感情败类 2021-02-09 18:45

I\'ve looked this up and the outlook seems bleak. I\'m not interested in using a table. I have 6 or so \'a element\' inline-blocks that make up a menu. It\'s slick, except all t

9条回答
  •  星月不相逢
    2021-02-09 19:02

    If you need it centered and dynamically shrinking/expanding to accommodate the content without knowing the width, then your only option really is using a table. It is the only elastic element in HTML repertoire.

    Whatever...

    P.S. You can have a div to shrink dynamically as well by setting the float property to float:left or float:right. So it will stick to the left or the right, but you can't have it centered this way.

提交回复
热议问题