LoginSignup
6
3

More than 5 years have passed since last update.

flex-boxで作るサムネイル付きリスト(左辺固定、右辺可変の縦中央寄せ)

Last updated at Posted at 2016-11-04

左辺固定(サムネイルとか)、右可変(テキストコンテンツ)みたいなレイアウトの構造をflex-boxで表現する時のベースコード。

flex-box.png

今までも以下のようなやり方があったけど、コードが長かったりセマンティックな感じでなくモヤモヤしてた感じ
- 古典的なtableタグを使うやり方
- display:table,display:table-cellを駆使していくやり方

flex-boxを使う利点

  • コードを短縮できる
  • 縦方向の中央寄せが簡単
html

<div class="item">
  <div class="thumb">
    <img src="hoge.png" alt="hogehoge">
  </div>
  <div class="content">
    <p>thumbの説明テキストが入りますよ</p>
  </div>
</div>
sass
.item {
  display: flex;
  align-items: center;
}

.thmb {
  width: 100px;
}

.content {
  flex: 1;
}
6
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
3