W3C home > Mailing lists > Public > www-style@w3.org > August 2016

Re: [css-page-floats] float: center?

From: Oriol Bugzilla <oriol-bugzilla@hotmail.com>
Date: Tue, 9 Aug 2016 17:54:25 +0000
To: Sam Davidson <samuelryandavidson@gmail.com>, "www-style@w3.org" <www-style@w3.org>
Message-ID: <VI1PR09MB00297090C73BBDD7E305C3A5971C0@VI1PR09MB0029.eurprd09.prod.outlook.com>
> Intuitively, this would center a box in its containing element and also cause it to take the width of its contained text


A CSS WG member would probably explain it better, but floats do more than alignment and shrink-to-fit.

They are also out-of-flow and have some behaviors which might not be obvious how should generalize in float:center or other arbitrary positions.


If you only want centering and shrink-to-fit, you can use

margin: 0 auto; /* Center horizontally */
width: fit-content; /* shrink-to-fit */

The latter may need vendor prefixes.

Other possibilities are display:inline-block, CSS tables, flexbox, etc.

Oriol
Received on Tuesday, 9 August 2016 17:54:59 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 9 August 2016 17:55:00 UTC