Flexbox(Flexible Box Layout)は、要素を柔軟に配置するためのCSSレイアウトモジュールです。
Flexboxは親要素(コンテナ)と子要素(アイテム)で構成されます。
/* 親要素にdisplay: flexを指定 */
.flex-container {
display: flex;
}
/* 子要素は自動的にflexアイテムになる */
.flex-item {
/* 個別のスタイル */
}
Flexboxには2つの軸があります:
.flex-container {
display: flex;
flex-direction: row;
justify-content: flex-start;
align-items: stretch;
flex-wrap: nowrap;
}
flex | inline-flex
Flexboxを有効化
row | column
アイテムの並ぶ方向
主軸方向の配置
center, space-between等
交差軸方向の配置
center, stretch等
wrap | nowrap
折り返しの設定
アイテム間の余白
gap: 1rem;
伸びる比率
余白を埋める
縮む比率
スペース不足時
基準サイズ
初期の幅・高さ
個別の配置
align-itemsを上書き
表示順序
HTMLと異なる順序
省略記法
flex: 1 1 auto;
.center-box {
display: flex;
justify-content: center; /* 横方向中央 */
align-items: center; /* 縦方向中央 */
height: 200px;
}
.nav {
display: flex;
justify-content: space-between; /* 両端揃え */
align-items: center;
}
.card-container {
display: flex;
flex-wrap: wrap; /* 折り返し有効 */
gap: 1rem; /* アイテム間の余白 */
}
.card {
flex: 1 1 300px; /* 最小300px、余白は均等に */
}
あなたのケースでの最適な解決方法:
footer {
background: rgba(255, 255, 255, 0.95);
backdrop-filter: blur(10px);
border-top: 1px solid rgba(255, 255, 255, 0.2);
margin-top: 3rem;
}
.footer-content {
display: flex; /* Flexboxを有効化 */
flex-direction: column; /* 縦並び */
align-items: center; /* 横方向中央(交差軸) */
justify-content: center; /* 縦方向中央(主軸) */
padding: 2rem 0;
}
.footer-text {
margin: 0; /* marginは不要 */
}
© 2025 ゆうか. All Rights Reserved.
なぜこれで解決するのか:
display: flex でFlexboxを有効化flex-direction: column で子要素を縦並びにalign-items: center で横方向(交差軸)の中央揃えjustify-content: center で縦方向(主軸)の中央揃え