使div扩展到一定的大小

时间:2021-09-05 20:27:10

I have a div on my page, and I want to make it expand to a certain size and then stop. Right now I have...

我的页面上有一个div,我想让它扩展到一定的大小然后停止。现在我有......

div {height:300px; width:700px; overflow:auto;}

The overflow attribute makes it scroll, but until then, I would like it to expand with the content. I have a text box below this and it looks bad with a text box floating down part of the page. Is there a way to have both of these attributes? All of the hits I found on Google were about making it expand to fit the content. Thanks!

overflow属性使其滚动,但在此之前,我希望它随内容扩展。我在这下面有一个文本框,看起来很糟糕,文本框浮动在页面的一部分。有没有办法同时拥有这两个属性?我在Google上发现的所有点击都是为了扩展以适应内容。谢谢!

2 个解决方案

#1


3  

Try using max-height.

尝试使用max-height。

This will allow you to specify the maximum height the box can be and once it reaches this height it will scroll as you've specified.

这将允许您指定框的最大高度,一旦达到此高度,它将按您指定的方式滚动。

#2


0  

Did you mean you want the div to have its height variable, depending on the size of content? Then just give height: auto instead of giving a fixed height of 300px. height: auto will adjust the height of the div based on the content size. Also define max-height property if you want to limit the maximum height the div can extend to.

你的意思是你希望div的高度可变,具体取决于内容的大小?然后给高度:auto而不是给出300px的固定高度。 height:auto将根据内容大小调整div的高度。如果要限制div可以扩展到的最大高度,还要定义max-height属性。

#1


3  

Try using max-height.

尝试使用max-height。

This will allow you to specify the maximum height the box can be and once it reaches this height it will scroll as you've specified.

这将允许您指定框的最大高度,一旦达到此高度,它将按您指定的方式滚动。

#2


0  

Did you mean you want the div to have its height variable, depending on the size of content? Then just give height: auto instead of giving a fixed height of 300px. height: auto will adjust the height of the div based on the content size. Also define max-height property if you want to limit the maximum height the div can extend to.

你的意思是你希望div的高度可变,具体取决于内容的大小?然后给高度:auto而不是给出300px的固定高度。 height:auto将根据内容大小调整div的高度。如果要限制div可以扩展到的最大高度,还要定义max-height属性。