Tips & Tricks

Claude Code के साथ Flexbox

Claude Code का उपयोग करके flexbox सीखें। Practical tips और code examples शामिल हैं।

Flexboxの頻出patternको Claude Code से一気にimplementation

Flexboxは1अगला元layoutの定番技術 है।Claude Codeにimplementationを依頼するとき、よくuse करनाpatternを知っておくと指示がspecificallyなり、より正確な結果を得られ है।

> Flexboxでresponsiveなnavigationバーをबनाओ。
> ロゴबाएं寄せ、menuदाएं寄せ、モバイルでハンバーガーmenu。
/* headernavigation */
.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;
}

センタリングpattern

/* 完全में央配置 */
.center-perfect {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

/* テキストとiconの垂直में央揃え */
.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;
}

cardlayout

/* 等幅card */
.card-row {
  display: flex;
  gap: 1.5rem;
}

.card-row .card {
  flex: 1;
  min-width: 0; /* テキスト溢れ防止 */
}

/* footer固定card */
.card {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.card__body {
  flex: 1; /* 残りのスペースを占有 */
}

.card__footer {
  margin-top: auto; /* 常にनीचेに配置 */
}

Holy Graillayout

/* 伝統的な3columnlayout */
.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;
}
/* footerを常にpageनीचे部に */
.page-wrapper {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.page-content {
  flex: 1;
}

/* footer は自動的にनीचे部に */

タグ・チップのラップ配置

/* タグlist */
.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;
}

入力fieldとbuttonの結合

/* searchバー */
.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切り替え

/* デスクトップ:横並び → モバイル:縦並び */
.responsive-flex {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

@media (width >= 768px) {
  .responsive-flex {
    flex-direction: row;
  }
}

/* 逆順display(モバイルで画像をऊपरに) */
@media (width < 768px) {
  .feature-section {
    flex-direction: column-reverse;
  }
}

Flexboxのdebug Tips

/* debug用:全要素にborder */
.debug-flex * {
  outline: 1px solid rgba(255, 0, 0, 0.2);
}

/* 各アイテムのsizeを視覚化 */
.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;
}

Summary

FlexboxはCSS Gridと使い分ける बातがポイント है।1अगला元のlayoutにはFlexbox、2अगला元のlayoutにはCSS Gridが適してい है।Claude Codeに「Flexboxで横並びにして」と指示する से ही、gapsettingsやmin-width: 0の考慮 तक शामिलimplementation generateしてくれ है।CSSvariable के साथ combineてデザインtokenをutilizationするのもおすすめ है।Flexboxの仕様詳細はCSS Flexible Box Layout Module confirmして करें।

#Claude Code #Flexbox #CSS #layout #frontend