2
4

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.

【CSS】比率で配置できるFlexboxのflexプロパティ

Posted at

はじめに

  • 比率で配置できるFlexboxのflexプロパティについてのまとめです。

flex:数値 比率で配置する

  • アイテムをどのような比率で配置するか
html
<!DOCTYPE html>
<html lang="ja">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <link rel="stylesheet" href="style.css" />
  </head>
  <body style="margin: 0">
    <div class="container">
      <div class="item item1">Item 1</div>
      <div class="item item2">Item 2</div>
    </div>
  </body>
</html>

下記のコードの場合、1対3の比率で配置できる

css
.container{
  display: flex;
}

.item1 {
  background-color: pink;
  flex: 1;
}

.item2 {
  background-color: blue;
  flex: 3;
}
FireShot Capture 075 - Document - .png
2
4
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
2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?