希望div宽度由内容决定(就像表一样) [英] want div width to be determined by contents (just like tables)

查看:68
本文介绍了希望div宽度由内容决定(就像表一样)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,我不想指定div的宽度。相反,我只想让它扩展到足够宽以包含其内容。

由于这就是表的行为方式,我尝试设置div {display:

table;}"它工作 - 但只在Firefox中,但不在IE6中。是否有任何替代品?
?我是否一个人需要这种类型的功能?


谢谢。

Often times, I do not want to specify the width of a div. Rather, I
just want it to expand to be just wide enough to enclose its contents.
Since this is how tables behave, I tried setting "div {display:
table;}" and it worked - but only in firefox, but not in IE6. Are there
any alternatives? Am I alone in needing this type of functionality?

Thank You.

推荐答案

"李" < CR ************* @ yahoo.com>写道:
"Lee" <cr*************@yahoo.com> wrote:
经常,我不想指定div的宽度。相反,我只是希望它扩展到足够宽以包含其内容。
由于这就是表的行为,我尝试设置div {display:
table;} ;它工作 - 但只在Firefox中,但不在IE6中。是否有其他选择?
Often times, I do not want to specify the width of a div. Rather, I
just want it to expand to be just wide enough to enclose its contents.
Since this is how tables behave, I tried setting "div {display:
table;}" and it worked - but only in firefox, but not in IE6. Are there
any alternatives?




< span>可能是答案,或显示:内联或显示:内联块,

只有当你告诉我们你实际上是在做什么时才能提供适当的建议。


-

Spartanicus



<span> might be the answer, or display:inline, or display:inline-block,
proper advice is only possible if you tell us what you are actually
trying to do.

--
Spartanicus


您好Spartanicus - 谢谢您的回复。


我有以下代码:


< div style =" border:1px solid black;">

< div style =" width:100px;边框:1px纯蓝色;"> 100px固定宽度

内部div< / div>

< div style =" width:200px;边框:1px纯蓝色;"> 200px固定宽度

内部div< / div>

< / div>


我希望外部div宽度自动计算为与其最大子元素相同的宽度(即:第二个200px宽子div)。这是
表格的行为方式,我想找到一种让div表现得好的方法

相同(不幸的是,设置display:table;" doesn工作

ie6)。


谢谢。

Hi Spartanicus - thank you for your reply.

I have the following code:

<div style="border: 1px solid black;">
<div style="width: 100px; border: 1px solid blue;">100px fixed width
inner div</div>
<div style="width: 200px; border: 1px solid blue;">200px fixed width
inner div</div>
</div>

I want the outer div width to automatically be computed to be the same
width as its largest child (ie: the 2nd 200px wide child div). This is
how tables behave and I would like to find a way to make divs behave
the same (unfortunately, setting "display: table;" doesn''t work on
ie6).

Thank you.


"理QUOT; < CR ************* @ yahoo.com>写道:
"Lee" <cr*************@yahoo.com> wrote:
嗨Spartanicus - 谢谢你的回复。


如果您坚持使用称为Google Groups的可怕现象

那么至少要学会尊重这里适用的发布惯例,

看看这个: http://www.safalra.com/ special / googlegroupsreply /

我有以下代码:

< div style =" border:1px solid black;">
< div style =" width:100px; border:1px solid blue;"> 100px fixed width
inner div< / div>
< div style =" width:200px;边框:1px纯蓝色;"> 200px固定宽度
内部div< / div>
< / div>

我想自动计算外部div宽度宽度与其最大的孩子相同(即:第二个200px宽的儿童div)。这是表格表现的方式,我想找到一种让div表现得相同的方法(不幸的是,设置display:table;不起作用
ie6 )。
Hi Spartanicus - thank you for your reply.
If you insist on using the horrible phenomena known as Google Groups
then at least learn to respect the posting conventions that apply here,
have a look at this: http://www.safalra.com/special/googlegroupsreply/
I have the following code:

<div style="border: 1px solid black;">
<div style="width: 100px; border: 1px solid blue;">100px fixed width
inner div</div>
<div style="width: 200px; border: 1px solid blue;">200px fixed width
inner div</div>
</div>

I want the outer div width to automatically be computed to be the same
width as its largest child (ie: the 2nd 200px wide child div). This is
how tables behave and I would like to find a way to make divs behave
the same (unfortunately, setting "display: table;" doesn''t work on
ie6).




这可能充其量只是你认为解决了一个尚未确定的问题的解决方案。这没有任何帮助,通常很大一部分问题

是人们认为的解决方案是错误的。在你通过向我们展示你真正想要做的事情分享

问题之前,我们可以为你做的事情并不多。

-

Spartanicus



That may at best qualify as your perceived solution to a still
unidentified problem. This doesn''t help, often a big part of the problem
is that people''s perceived solutions are wrong. Until you share the
problem by showing us what you are really trying to do there''s not much
we can do for you.

--
Spartanicus


这篇关于希望div宽度由内容决定(就像表一样)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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