height
åºçº¿
广æ³å¯ç¨
*
èª 2015å¹´7æ èµ·ï¼æ¤ç¹æ§å·²å¨ä¸»æµæµè§å¨ä¸å¾å°æ¯æï¼å¯å¨å¤§å¤æ°è®¾å¤åæµè§å¨çæ¬ä¸æ£å¸¸ä½¿ç¨ã
* æ¤ç¹æ§çæäºé¨åçæ¯æç¨åº¦å¯è½ææä¸åã
height CSS 屿§æå®äºä¸ä¸ªå
ç´ çé«åº¦ãé»è®¤æ
åµä¸ï¼è¿ä¸ªå±æ§å³å®çæ¯å
容åºï¼ content areaï¼çé«åº¦ï¼ä½æ¯ï¼å¦æå° box-sizing 设置为 border-box , è¿ä¸ªå±æ§å³å®çå°æ¯è¾¹æ¡åºåï¼border areaï¼çé«åº¦ã
å°è¯ä¸ä¸
height: 150px;
height: 6em;
height: 75%;
height: auto;
<section class="default-example" id="default-example">
<div class="transition-all" id="example-element">
This is a box where you can change the height.
</div>
</section>
#example-element {
display: flex;
flex-direction: column;
background-color: #5b6dcd;
justify-content: center;
color: #ffffff;
}
min-height å max-height 屿§ä¼è¦ç heightã
è¯æ³
/* Keyword value */
height: auto;
/* <length> values */
height: 120px;
height: 10em;
/* <percentage> value */
height: 75%;
/* Global values */
height: inherit;
height: initial;
height: unset;
å¼
<length>-
å°é«åº¦å®ä¹ä¸ºä¸ä¸ªç»å¯¹å¼ã
<percentage>-
å°é«åº¦å®ä¹ä¸ºç¸å¯¹å å«åé«åº¦çç¾åæ¯ã
border-box-
å¦æè®¾ç½®è¯¥å¼ï¼å
<length>æè<percentage>ä¼è®¾ç½®ä¸ºè¯¥å ç´ ç border boxã content-box-
å¦æè®¾ç½®è¯¥å¼ï¼å
<length>æè<percentage>ä¼è®¾ç½®ä¸ºè¯¥å ç´ ç content boxã auto-
ç±æµè§å¨ä¸ºå ç´ è®¡ç®å¹¶éæ©ä¸ä¸ªé«åº¦ã
fill-
æ ¹æ®æåæ¹åï¼ä½¿ç¨
fill-availableä½ä¸ºè¡å¤§å°æè å大å°ã max-content-
设置为å 许çæå¤§é«åº¦ã
min-content-
设置为å 许çæå°é«åº¦ã
available-
å å«åé«åº¦åå»å½åå ç´ çè¾¹è·ï¼è¾¹æ¡åå¡«å ã
fit-content-
å° fill-content å ¬å¼ä¸çå¯ç¨ä½ç½®æ¿æ¢ä¸ºç¹å®ç忰以è¿è¡ä½¿ç¨ï¼å¦ï¼min(max-content, max(min-content, ))
Formal syntax
height =
auto |
<box-size> |
<anchor-size()> |
contain |
fit-content( <length-percentage [0,â]> )
<box-size> =
<length-percentage> |
stretch |
contain |
min-content |
max-content |
fit-content |
fit-content( ) |
calc-size( )
<anchor-size()> =
anchor-size( [ <anchor-name> || <anchor-size> ]? , <length-percentage>? )
<length-percentage> =
<length> |
<percentage>
<anchor-name> =
<dashed-ident>
<anchor-size> =
width |
height |
block |
inline |
self-block |
self-inline
示ä¾
>HTML
<div id="taller">I'm 50 pixels tall.</div>
<div id="shorter">I'm 25 pixels tall.</div>
<div id="parent">
<div id="child">I'm half the height of my parent.</div>
</div>
CSS
div {
width: 250px;
margin-bottom: 5px;
border: 2px solid blue;
}
#taller {
height: 50px;
}
#shorter {
height: 25px;
}
#parent {
height: 100px;
}
#child {
height: 50%;
width: 75%;
}
ç»æ
æ éç¢é®é¢
ç¡®ä¿è®¾å®äº height çå
ç´ å¨æ¾ç¤ºä¸ä¸ä¼è¢«æªæï¼æè
å½é¡µé¢æ¾å¤§æ¶å¢å¤§çåä½å¤§å°ä¸ä¼é®æ¡å
¶ä»å
容ã
è§è
| è§è |
|---|
| CSS Box Sizing Module Level 3 > # preferred-size-properties > |
| CSS Box Sizing Module Level 3 > # sizing-values > |
| åå§å¼ | auto |
|---|---|
| éç¨å ç´ | éç¨äºææå ç´ ï¼ä½ä¸å æ¬éæ¿æ¢è¡çº§å ç´ ãè¡¨æ ¼åååç» |
| æ¯å¦æ¯ç»§æ¿å±æ§ | å¦ |
| Percentages | The percentage is calculated with respect to the height of the generated box's containing block. If the height of the containing block is not specified explicitly (i.e., it depends on content height), and this element is not absolutely positioned, the value computes to auto. A percentage height on the root element is relative to the initial containing block. |
| 计ç®å¼ | a percentage or auto or the absolute length |
| å¨ç»ç±»å | a length, percentage or calc(); |