Flexbox:Claude Code 实战指南
了解flexbox:Claude Code 实战. 包含实用技巧和代码示例。
Flexboxの頻出パターンを通过 Claude Code一気に实现
Flexboxは1次元布局の定番技術です。让 Claude Code实现を依頼するとき、よく使うパターンを知っておくと指示が具体地なり、より正確な結果を得られます。
导航バー
> Flexboxで响应式な导航バー创建。
> ロゴ左寄せ、菜单右寄せ、モバイルでハンバーガー菜单。
/* ヘッダーナビゲーション */
.navbar {
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 1.5rem;
height: 60px;
}
.navbar__logo {
flex-shrink: 0;
}
.navbar__menu {
display: flex;
gap: 1.5rem;
list-style: none;
}
.navbar__actions {
display: flex;
align-items: center;
gap: 0.75rem;
margin-left: auto;
}
センタリングパターン
/* 完全中央配置 */
.center-perfect {
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
}
/* テキストとアイコンの垂直中央揃え */
.inline-center {
display: flex;
align-items: center;
gap: 0.5rem;
}
/* 複数行テキストの中央配置 */
.text-center-block {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
text-align: center;
}
カード布局
/* 等幅カード */
.card-row {
display: flex;
gap: 1.5rem;
}
.card-row .card {
flex: 1;
min-width: 0; /* テキスト溢れ防止 */
}
/* フッター固定カード */
.card {
display: flex;
flex-direction: column;
height: 100%;
}
.card__body {
flex: 1; /* 残りのスペースを占有 */
}
.card__footer {
margin-top: auto; /* 常に下に配置 */
}
Holy Grail布局
/* 伝統的な3カラムレイアウト */
.holy-grail {
display: flex;
flex-direction: column;
min-height: 100vh;
}
.holy-grail__body {
display: flex;
flex: 1;
}
.holy-grail__main {
flex: 1;
min-width: 0;
padding: 1.5rem;
}
.holy-grail__sidebar {
flex: 0 0 250px;
padding: 1.5rem;
}
.holy-grail__sidebar--left {
order: -1;
}
Sticky Footer
/* フッターを常にページ下部に */
.page-wrapper {
display: flex;
flex-direction: column;
min-height: 100vh;
}
.page-content {
flex: 1;
}
/* footer は自動的に下部に */
タグ・チップのラップ配置
/* タグ一覧 */
.tag-list {
display: flex;
flex-wrap: wrap;
gap: 0.5rem;
}
.tag {
flex-shrink: 0;
padding: 0.25rem 0.75rem;
border-radius: 9999px;
font-size: 0.875rem;
background: #e5e7eb;
}
输入フィールドと按钮の結合
/* 検索バー */
.search-bar {
display: flex;
}
.search-bar__input {
flex: 1;
border: 1px solid #d1d5db;
border-right: none;
border-radius: 0.5rem 0 0 0.5rem;
padding: 0.5rem 1rem;
min-width: 0;
}
.search-bar__button {
flex-shrink: 0;
border-radius: 0 0.5rem 0.5rem 0;
padding: 0.5rem 1rem;
background: #3b82f6;
color: white;
}
响应式切换
/* デスクトップ:横並び → モバイル:縦並び */
.responsive-flex {
display: flex;
flex-direction: column;
gap: 1rem;
}
@media (width >= 768px) {
.responsive-flex {
flex-direction: row;
}
}
/* 逆順表示(モバイルで画像を上に) */
@media (width < 768px) {
.feature-section {
flex-direction: column-reverse;
}
}
Flexboxの调试 Tips
/* デバッグ用:全要素にボーダー */
.debug-flex * {
outline: 1px solid rgba(255, 0, 0, 0.2);
}
/* 各アイテムのサイズを視覚化 */
.debug-flex > * {
position: relative;
}
.debug-flex > *::after {
content: attr(class) " | " attr(style);
position: absolute;
top: 0;
left: 0;
font-size: 10px;
background: rgba(0, 0, 0, 0.7);
color: white;
padding: 2px 4px;
}
总结
FlexboxはCSS Gridと使い分けることがポイントです。1次元の布局にはFlexbox、2次元の布局にはCSS Gridが適しています。让 Claude Code「Flexboxで横並びにして」と指示する只需、gap配置やmin-width: 0の考慮まで含めた实现を生成してくれます。CSS变量と組み合わせてデザインTokenを活用するのもおすすめです。Flexboxの仕様详细信息请参阅CSS Flexible Box Layout Module请确认。
#Claude Code
#Flexbox
#CSS
#レイアウト
#frontend
Related Posts
Tips & Tricks
Tips & Tricks
10 个技巧让你的 Claude Code 生产力翻三倍
分享 10 个实用的 Claude Code 使用技巧。从提示词策略到工作流优化,这些方法让你今天就能提升效率。
Tips & Tricks
Tips & Tricks
Canvas/WebGL Optimization:Claude Code 实战指南
了解canvas/webgl optimization:Claude Code 实战. 包含实用技巧和代码示例。
Tips & Tricks
Tips & Tricks
Markdown Implementation:Claude Code 实战指南
了解markdown implementation:Claude Code 实战. 包含实用技巧和代码示例。