さまざまな align-content
値を試す
このステップでは、複数行のコンテナ内の Flex 要素のレイアウトにどのように影響するかを理解するために、さまざまな align-content
プロパティ値を試してみます。さまざまな整列オプションを試すために CSS を更新します。
<style>
.flex-container {
display: flex;
flex-wrap: wrap;
width: 300px;
height: 300px;
border: 2px solid #333;
background-color: #f0f0f0;
/* さまざまな align-content 値を解除コメントにして、その効果を確認します */
/* align-content: stretch; */
/* align-content: flex-start; */
/* align-content: flex-end; */
/* align-content: center; */
/* align-content: space-between; */
/* align-content: space-around; */
}
.flex-item {
width: 100px;
height: 100px;
margin: 5px;
background-color: #4CAF50;
color: white;
display: flex;
justify-content: center;
align-items: center;
font-family: Arial, sans-serif;
}
</style>
これらの align-content
値を調べましょう。
stretch
(既定値):コンテナを埋めるようにラインを伸縮させます。
flex-start
:コンテナの先頭にラインを整列させます。
flex-end
:コンテナの末尾にラインを整列させます。
center
:コンテナ内でラインを中央に配置します。
space-between
:ライン間に均等な余白を持って配置します。
space-around
:ラインの周りに均等な余白を持って配置します。
例の出力の可視化:
stretch: flex-start: flex-end:
+----------+ +----------+ +----------+
| 1 2 3 | | 1 2 3 | | 1 2 3 |
| 4 5 6 | | | | |
+----------+ +----------+ +----------+
center: space-between: space-around:
+----------+ +----------+ +----------+
| 1 2 3 | | 1 2 3 | | 1 2 3 |
| 4 5 6 | | | | |
+----------+ +----------+ +----------+
理解すべき要点:
- さまざまな
align-content
値の解除コメントを行います。
- コンテナ内でラインがどのように配置されているかを観察します。
- 各整列オプションの影響を理解します。