1
1

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 3 years have passed since last update.

きっちり等間隔に3等分する方法

Last updated at Posted at 2020-12-29

CSSで計算式を可能にするcalcの紹介です。

めちゃくちゃ便利。

何がしたいか

フッターの要素を3等分したい。(アプリによくあるフッター要素みたいなのを作りたかった)

<div class="footer-container">
  <div class="container">要素A</div>
  <div class="container">要素B</div>
  <div class="container">要素C</div>
</div>

この要素A〜Cをそれぞれきれいに3等分にしたい。

書き方

.footer-container > .container {
  width: calc(100% / 3);
}

これだけ。

でも、これだとブラウザ(主にIE)のバージョンによっては対応していないこともあるので、必要な場合は下記。

.footer-container > .container {
  width: calc(100% / 3);
  width: 33.333% ;
}

参考

公式そのまま
https://developer.mozilla.org/ja/docs/Web/CSS/calc()

1
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?