View Full Version : inline-block w/ auto width question
01-04-2007, 12:07 AM
display:inline-block; float:left; width:auto;
I can have the width of the DIV auto adjust to the contents within the DIV. Is it possible however to have the entire DIV float in the middle using the same technique? I have already tried margin-right:auto; margin-left:auto to no avail. Any ideas? Thanks in advance.
01-04-2007, 03:39 AM
Just so you know, using display: inline-block and float: left at the same time is pointless since floated elements are by nature block (and not inline) elements. The float declaration will override the display declaration in this case.
To get the centered, shrink‐wrapped effect that you seem to want, you would use display: inline-block and text-align: center. To make that more clear, the text-align property might be more properly called the “inline-align” property; inline‐block elements are inline and so must be centered with the inline method, not the block method of margin: … auto.
The above solution presents some compatibility problems though since Firefox does not support display: inline-block yet, and Internet Explorer only supports display: inline-block on elements that are inline by default. You can use the proprietary -moz-inline-block value for (Mozilla) Firefox instead, but it’s a poor substitute and has bugs associated with it.
Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.