GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||
GeezerVison is showing developer.mozilla.org — height CSS property - CSS | MDN
|
| Initial value | auto |
|---|---|
| Applies to | all elements but non-replaced inline elements, table columns, and column groups |
| Inherited | no |
| 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. |
| Computed value | a percentage or auto or the absolute length |
| Animation type | a length, percentage or calc(); |
height =
auto |
<box-size> |
<anchor-size()>
<box-size> =
<length-percentage [0,∞]> |
stretch |
contain |
min-content |
max-content |
fit-content |
stretch( <length-percentage [0,∞]> ) |
fit-content( <length-percentage [0,∞]> ) |
<calc-size()>
<anchor-size()> =
anchor-size( [ <anchor-name> || <anchor-size> ]? , <length-percentage>? )
<length-percentage> =
<length> |
<percentage>
<calc-size()> =
calc-size( <calc-size-basis> , <calc-sum> )
<anchor-name> =
<dashed-ident>
<anchor-size> =
width |
height |
block |
inline |
self-block |
self-inline
<calc-size-basis> =
<size-keyword> |
<calc-sum> |
<calc-size()> |
any
<calc-sum> =
<calc-product> [ [ '+' | '-' ] <calc-product> ]*
<calc-product> =
<calc-value> [ [ '*' | / ] <calc-value> ]*
<calc-value> =
<number> |
<dimension> |
<percentage> |
<calc-keyword> |
( <calc-sum> )
<calc-keyword> =
e |
pi |
infinity |
-infinity |
NaN
<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>
div {
width: 250px;
margin-bottom: 5px;
border: 2px solid blue;
}
#taller {
height: 50px;
}
#shorter {
height: 25px;
}
#parent {
height: 100px;
}
#child {
height: 50%;
width: 75%;
}
<div class="parent">
<div class="child">text</div>
</div>
<div class="parent">
<div class="child stretch">stretch</div>
</div>
@supports not (height: stretch) {
body::before {
content: "Your browser doesn't support the `stretch` value yet.";
background-color: wheat;
display: block;
text-align: center;
padding: 1rem 0;
}
}
.parent {
height: 150px;
margin: 1rem;
border: solid;
}
.child {
margin: 1rem;
background: #00999999;
}
.stretch {
height: stretch;
}
| Specification |
|---|
| CSS Box Sizing Module Level 3 # preferred-size-properties |
| CSS Box Sizing Module Level 3 # sizing-values |
widthbox-sizingmin-height, max-heightblock-size, inline-sizeanchor-size()clamp()minmax()height attribute