以不确定的大小为中心的div [英] Centered div of indeterminate size

查看:67
本文介绍了以不确定的大小为中心的div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我想在一个页面上水平居中一个div,但是具有

未定义宽度的div,那么它包含其中的任何内容,作为表格单元格

,我如何在CSS中编码?


Brian Tozer

If I want to horizontally center a div on a page, but have the div of
undefined width, so that it contains whatever is within it, as a table cell
does, how do I code this in CSS?

Brian Tozer

推荐答案

" KiwiBrian" ; <峰; br ****** @ ihug.co.nz>写道:
"KiwiBrian" <br******@ihug.co.nz> wrote:
如果我想在一个页面上水平居中一个div,但是具有未定义宽度的div,以便它包含其中的任何内容,作为一个表单元格
如何,我如何在CSS中编码?
If I want to horizontally center a div on a page, but have the div of
undefined width, so that it contains whatever is within it, as a table cell
does, how do I code this in CSS?




div {display:inline-block}


和包含块上的text-align {center}(IE不支持和

Mozilla)。


-

Spartanicus



div{display:inline-block}

and text-align{center} on the containing block (not supported by IE and
Mozilla).

--
Spartanicus


KiwiBrian写道:
KiwiBrian wrote:
如果我想在页面上水平居中一个div,但是div为
未定义的宽度,以便它包含其中的任何内容,如表格单元格那样,我如何在CSS中编码?
If I want to horizontally center a div on a page, but have the div of
undefined width, so that it contains whatever is within it, as a table cell
does, how do I code this in CSS?




Set div的宽度为auto,左边和右边

边距等于宽度。

对于IE5(和4)你需要text-align:center ;在父母

元素上。


-

Els
http://locusmeus.com/

Sonhos vem。 Sonhos v?o。 Orestoébritfeito。

- Renato Russo -



Set the width of the div to auto, and the left and right
margin to equal widths.
For IE5 (and 4) you''ll need text-align:center; on the parent
element.

--
Els
http://locusmeus.com/
Sonhos vem. Sonhos v?o. O resto é imperfeito.
- Renato Russo -


Els< el ********* @ tiscali.nl>写道:
Els <el*********@tiscali.nl> wrote:
如果我想在一个页面上水平居中一个div,但是具有未定义宽度的div,那么它包含无论是什么内容,作为表格单元格
,我如何在CSS中编码?
If I want to horizontally center a div on a page, but have the div of
undefined width, so that it contains whatever is within it, as a table cell
does, how do I code this in CSS?



将div的宽度设置为auto



Set the width of the div to auto




你认为这是怎么回事?


-

Spartanicus



And what do you think this does?

--
Spartanicus


这篇关于以不确定的大小为中心的div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆