あなたがcalc()
とvh
/vw
に中継することができます(max-
)width
/height
。
header {
background: pink;
height: 150px;
}
header, .squarred {/* use flex for centering, optionnal */
display: flex;
align-items: center;
justify-content: center;
flex-direction: ;
}
.squarred {
width:calc(100vh - 150px);/* luck: header has a fixed height , remove it */
max-width:100vw;/* stay within the window */
max-height:100vw;/* stay within the window */
margin:0 auto;
flex:1;
overflow:auto;/* can be usefull */
background:turquoise;
}
html,body {/* set the frame */
margin:0;
height:100vh;
display:flex;
flex-direction:column;
}
<header><h1>header</h1></header>
<main class="squarred">
<div class="buffer">
<h2>I am a square</h2>
<p>I occupy the remaining space</p>
</div>
https://codepen.io/gc-nomade/full/MOVQWZ/
パディングが失敗した場合、あなたはこれまでに使用してみました、あなたのHTMLの構造とCSSを共有することができます。スクリーンショットは役に立ちませんが、仕事をするためです。 –
....私はCSSの答えを持っています...それは動作しますが、あなたがどこで失敗したのかわからず、どこで助けてくれるのでしょうか? –
G-Cyr、なぜ私の質問で詰めが失敗するのか説明します。 1つの次元(幅または高さ)に基づいて縦横比を設定することのみが可能です。 –