Re: [css-d] Centering contained div with unknown width.
J.C. Berry wrote: Hello all, I have the below link to a problem. I have an absolute page and container width, but I have a div inside the container that I need centered no matter how wide that contained div is. How can I make the contained div only as wide as its content and center it? Make the contained DIV display: inline-block and the surrounding DIV text-align: center ? Not tested, but based on previous work that used these ideas. Philip Taylor __ css-discuss [css-d@lists.css-discuss.org] http://www.css-discuss.org/mailman/listinfo/css-d List wiki/FAQ -- http://css-discuss.incutio.com/ List policies -- http://css-discuss.org/policies.html Supported by evolt.org -- http://www.evolt.org/help_support_evolt/
Re: [css-d] Centering contained div with unknown width.
You need to have margin-left and margin-right to be auto something like this: #container { width: 960px; background-color: silver; } #contained { width: 500px; margin: 0 auto; background-color: gray; } Your HTML might look like this: div id=container div id=containedContained/div /div If this doesn't help then please post a link to your page for us to have a look at the source code. Good luck. I have the below link to a problem. I have an absolute page and container width, but I have a div inside the container that I need centered no matter how wide that contained div is. How can I make the contained div only as wide as its content and center it? http://mindarc.com/capture.JPG __ css-discuss [css-d@lists.css-discuss.org] http://www.css-discuss.org/mailman/listinfo/css-d List wiki/FAQ -- http://css-discuss.incutio.com/ List policies -- http://css-discuss.org/policies.html Supported by evolt.org -- http://www.evolt.org/help_support_evolt/
Re: [css-d] Centering contained div with unknown width.
Le 30 mars 2013 à 03:28, J.C. Berry jcharlesbe...@gmail.com a écrit : I have the below link to a problem. I have an absolute page and container width, but I have a div inside the container that I need centered no matter how wide that contained div is. How can I make the contained div only as wide as its content and center it? http://mindarc.com/capture.JPG Assuming the following markup: div class=container div class=contained shrink-wrapping and centred/div /div Then display: table will do what you want, I think If I understand correctly - a simple html test case would be more useful than an image…): .contained { display: table; margin: 1em auto; } Philippe -- Philippe Wittenbergh http://l-c-n.com __ css-discuss [css-d@lists.css-discuss.org] http://www.css-discuss.org/mailman/listinfo/css-d List wiki/FAQ -- http://css-discuss.incutio.com/ List policies -- http://css-discuss.org/policies.html Supported by evolt.org -- http://www.evolt.org/help_support_evolt/