0
0

【CSS初学者】フレックスボックスのプロパティ学習①

Posted at

はじめに

CSSのフレックスボックスのプロパティを勉強のためにまとめました。
第一弾として、下記の動作を確認しました。
 ・flex-direction(主軸方向の設定)
 ・justify-content(左右の配置指定)
 ・align-items(上下の配置指定)

初期状態

index.html
<body>
    <div class="container">
        <div class="flexItem_1">
            <p>1</p>
        </div>
        <div class="flexItem_2">
            <p>22</p>
        </div>
        <div class="flexItem_3">
            <p>333</p>
        </div>
    </div>
</body>
style.css
.container{
    border: 5px pink solid;
}

.container>div{
    padding: 10px;
    margin: 10px;
}

.flexItem_1{
    background-color: greenyellow;
}

.flexItem_2{
    background-color: yellow;
}

.flexItem_3{
    background-color: red;
}

image.png

containerにflexを追加してフレックスボックスにする

style.css
.container{
    border: 5px pink solid;
    display: flex; /*  display: flex を追加 */
}

image.png

〇flex-direction(主軸方向の設定)

・row(規定値)

style.css
.container{
    (省略)
    flex-direction: row;
}

image.png

・columon

style.css
.container{
    (省略)
    flex-direction: column;
}

image.png

・row-reverse

style.css
.container{
    (省略)
    flex-direction: row-reverse;
}

image.png

・columon-reverse

style.css
.container{
    (省略)
    flex-direction: column-reverse;
}

image.png

〇justify-content(左右の配置指定)

・start

style.css
.container{
    (省略)
    justify-content: start;
}

image.png

・center

style.css
.container{
    (省略)
    justify-content: center;
}

image.png

・end

style.css
.container{
    (省略)
    justify-content: end;
}

image.png

・space-between

style.css
.container{
    (省略)
    justify-content: space-between;
}

image.png

・space-around

style.css
.container{
    (省略)
    justify-content: space-around;
}

image.png

・space-evenry

style.css
.container{
    (省略)
    justify-content: space-evenry;
}

image.png

〇align-items(上下の配置指定)

高さが必要なので、containerの高さを変更

.container{
    border: 5px pink solid;
    display: flex ;
    height:200px;
}

image.png

・strech

style.css
.container{
    (省略)
    align-items: strech;
}

image.png

・center

style.css
.container{
    (省略)
    align-items: center;
}

image.png

・start

style.css
.container{
    (省略)
    align-items: start;
}

image.png

・end

style.css
.container{
    (省略)
    align-items: end;
}

image.png

おわりに

今回確認したのは3つのプロパティのメインどころだけですが、
それでも沢山あるので使いこなせるか不安です。。。
使えるようになるまで精進します。

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