max-height
Baseline Widely available *
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.
* Some parts of this feature may have varying levels of support.
max-height は CSS のプロパティで、要素の最大高を設定します。これは height プロパティの使用値が、 max-height に指定した値を上回ることを防ぎます。
試してみましょう
max-height: 150px; max-height: 7em; max-height: 75%; max-height: 10px; <section class="default-example" id="default-example"> <div class="transition-all" id="example-element"> This is a box where you can change the maximum height. <br />This will limit how tall the box can be, potentially causing an overflow. </div> </section> #example-element { display: flex; flex-direction: column; background-color: #5b6dcd; justify-content: center; color: #ffffff; } max-height は height を上書きしますが、 min-height は max-height を上書きします。
構文
/* <length> 値 */ max-height: 3.5em; max-height: anchor-size(height); max-height: calc(anchor-size(--myAnchor self-block, 250px) + 2em); /* <percentage> 値 */ max-height: 75%; /* キーワード値 */ max-height: none; max-height: max-content; max-height: min-content; max-height: fit-content; max-height: fit-content(20em); max-height: stretch; /* グローバル値 */ max-height: inherit; max-height: initial; max-height: revert; max-height: revert-layer; max-height: unset; 値
<length>-
max-heightを絶対的な値で定義します。 <percentage>-
max-heightを包含ブロックの高さに対するパーセント値で定義します。 none-
ボックスの寸法を制限しません。
max-content-
内容物が推奨する
max-heightです。 min-content-
内容物の最小の
max-heightです。 fit-content-
利用できる空間を使用しますが、 max-content を超えないようにします。すなわち、
min(max-content, max(min-content, stretch))です。 fit-content(<length-percentage>)-
利用可能な空白を指定された引数で置き換えた
fit-content式を使用します。すなわち、min(max-content, max(min-content, 引数))です。 stretch-
要素のマージンボックスの最大の高さを、包含ブロックの高さに制限します。マージンボックスが包含ブロック内で利用できる空間をすべて満たそうとするため、
100%と似たような動作をしますが、結果として得られるサイズは box-sizing で決定されるボックスではなく、マージンボックスに適用されます。メモ: ブラウザーが
stretch値のために使用する別名と実装状況については、ブラウザーの互換性の節を参照してください。
アクセシビリティ
テキストを大きくするためにページを拡大したときに、 max-height を設定した要素が切り取られたり、他のコンテンツを覆い隠したりしないことを確認してください。
公式定義
形式文法
max-height =
none |
<length-percentage [0,∞]> |
min-content |
max-content |
fit-content( <length-percentage [0,∞]> ) |
<calc-size()> |
<anchor-size()> |
stretch |
fit-content |
contain
<length-percentage> =
<length> |
<percentage>
<calc-size()> =
calc-size( <calc-size-basis> , <calc-sum> )
<anchor-size()> =
anchor-size( [ <anchor-name> || <anchor-size> ]? , <length-percentage>? )
<calc-size-basis> =
<size-keyword> |
<calc-size()> |
any |
<calc-sum>
<calc-sum> =
<calc-product> [ [ '+' | '-' ] <calc-product> ]*
<anchor-name> =
<dashed-ident>
<anchor-size> =
width |
height |
block |
inline |
self-block |
self-inline
<calc-product> =
<calc-value> [ [ '*' | / ] <calc-value> ]*
<calc-value> =
<number> |
<dimension> |
<percentage> |
<calc-keyword> |
( <calc-sum> )
<calc-keyword> =
e |
pi |
infinity |
-infinity |
NaN
例
>パーセント値とキーワード値を用いた max-height の設定
table { max-height: 75%; } form { max-height: none; } 仕様書
| Specification |
|---|
| CSS Box Sizing Module Level 4> # sizing-values> |
ブラウザーの互換性
Loading…