LoginSignup
4
0

More than 5 years have passed since last update.

positon:absoluteのときに、横幅可変の要素を作る

Last updated at Posted at 2018-04-17

absoluteがきいているときでも、可変の要素を作りたい
transformとcalcを使う

SCSS
.text {
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 29px; //文字中央寄せのため
  border: 1px solid white;
  border-radius: 5px;
  position: absolute;
  bottom: 14px;
  left: 50%; //要素を左半分に寄せる
  transform: translateX(-50%); //寄せた位置から、要素の中心を50%右に寄せる
  width: calc(100% - 16px);
  height: 29px;
}
4
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
4
0