CSS 如何设置div的最小高度?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7155375/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set minimum height for a div?
提问by hraesvelgr
I have a page in which expanding content flows out of the holding div, the relevant CSS is below as well. Simply removing the height:510px line will allow the div to expand as needed. However, new users who have no content will not have any height and the page will look unblanced. How do I set a minimum height?
我有一个页面,其中扩展内容从保持 div 流出,相关的 CSS 也在下面。简单地删除 height:510px 行将允许 div 根据需要扩展。但是,没有内容的新用户不会有任何高度,页面看起来会不平衡。如何设置最小高度?
.Bb1
{
width:680px;
height:510px;
background-color:#ffffff;
float:left;
border-right:3px solid #edefed;
border-radius: 10px;
}
回答by hraesvelgr
CSS allows a "min-height" property. This can be used to set the minimum height of the div you're talking about.
CSS 允许使用“min-height”属性。这可用于设置您正在谈论的 div 的最小高度。
#div-id { min-height: 100px; }
回答by Zeeshan Siddiqui
Incase you want to set a minimum/maximum height and minimum/maximum width to a div
, CSS allows the specific feature.
如果您想将最小/最大高度和最小/最大宽度设置为 a div
,CSS 允许特定功能。
To set the minimum width of the div
or any other class/id/element, use;
要设置div
或任何其他类/ID/元素的最小宽度,请使用;
min-width: 150px;
To set the minimum height of the div
or any other class/id/element, use;
要设置该div
或任何其他类/ID/元素的最小高度,请使用;
min-height: 300px;
Similarly for setting maximum width and height of a div
or any other class/id/element, use;
类似地,要设置一个div
或任何其他类/ID/元素的最大宽度和高度,请使用;
max-width: 600px;
max-height: 600px;
Important:
重要的:
For your div
to expand freelyin height and width after data is available for users; you will have to set the width/height to auto
immediatelyafter you have set the min-width
or min-height
.
为了您div
以自由膨胀的高度和后可供用户数据宽度; 您必须在设置or后auto
立即设置宽度/高度。min-width
min-height
min-width: 300px;
width: auto;
min-height: 100px;
height: auto;
回答by Joseph Marikle
min-height:510px;
css has a min-height attribute
css 有一个 min-height 属性
回答by Mohit Singh
Here is d way through which you can set min height of a div
这是您可以设置 div 的最小高度的 d 方式
<div id="bb1" style="min-height:200px;>
.....
</div>
or apply
或申请
#bb1{
min-height:200px;
}
if you have used class
如果你使用过类
like
喜欢
<div class="bb1">
in div then use
在 div 然后使用
.bb1{
min-height:200px;
}
回答by Fred Ondieki
.comments { min-height:650px;height:auto; }
<div class="comments">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nam cursus. Morbi ut mi.</div>
回答by Bryce Figueiredo
Do this:
做这个:
.minHeight {
min-height: 100px;
height: auto;
border: 1px solid red;
/* IMPORTANT -- always set 'height: auto;' immediately after the min-height attribute */
}
<div class="minHeight">
this div has a min-height attribute
</div>