1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

可変サイズ・複数行にも対応 Flexboxを使った上下左右中央揃え

Last updated at Posted at 2019-03-11

ベンダープレフィックス(-webkit-)は古いsafariやiOS・AndroidでFlexboxを効かせるために書いてます

.center_box {
    display: -webkit-flex;
    display: flex;
    -webkit-flex-direction: column;
    flex-direction: column;
    -webkit-justify-content: center;
    justify-content: center;
    -webkit-align-items: center; /* 左右中央揃えにしたくない場合は削除 */
    align-items: center; /* 左右中央揃えにしたくない場合は削除 */
}
<div class="center_box">
<h1>center_boxで囲ったこれらの要素は上下左右中央揃えで表示されます</h1>
<p>複数行でも大丈夫です</p>
<img src="hoge.jpg" alt="画像もOK">
</div>

こんなときに

  • メインビジュアルの上にテキストを乗せたい
  • 画像を真ん中に置きたい
1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?