inblog logo
|
jjack1
    HTML/CSS

    [HTML/CSS] 6. CSS Flexbox

    최재원's avatar
    최재원
    Mar 11, 2025
    [HTML/CSS] 6. CSS Flexbox
    Contents
    1. Flex 기본 특징1. 기본 구조2. 축 이동justify-content: startjustify-content: endjustify-content: centeralign-items: startalign-items: centeralign-items: end3. 축 방향 변경flex-direction: rowflex-direction: column4. 공간 만들기justify-content: space-evenlyjustify-content: space-aroundjustify-content: space-between5. 요소 흐르기flex-wrap: nowrap;flex-wrap: wrap;6. 요소의 크기를 비율로 정하기

    1. Flex 기본 특징

    ❗
    유연한 레이아웃을 만들 수 있다.
    notion image
    notion image
    display: flex;
    • 자신은 block
    • 자식은 inline-block으로 만든다

    1. 기본 구조

    .f-box { display: flex; flex-wrap: wrap; } .b1 { flex: 1; }
    <div class="f-box"> <div class="b1">1</div> </div>
    • 부모 요소에 flex를 설정
    • 부모 요소에서 자식 요소의 위치를 설정 가능
    • 자식 요소의 크기는 자식 요소만 설정 가능

    2. 축 이동

    justify-content: start

    notion image
    display: flex; justify-content: start;
    • justify-content = 메인 축을 기준으로 이동한다

    justify-content: end

    notion image
    display: flex; justify-content: end;

    justify-content: center

    notion image
    display: flex; justify-content: center;

    align-items: start

    notion image
    display: flex; align-items: start; height: 500px;
    • align-item = cross축을 기준으로 이동한다

    align-items: center

    notion image
    display: flex; align-items: center; height: 500px;

    align-items: end

    notion image
    display: flex; align-items: end; height: 500px;

    3. 축 방향 변경

    flex-direction: row

    notion image
    display: flex; flex-direction: row;

    flex-direction: column

    notion image
    display: flex; flex-direction: column;

    4. 공간 만들기

    justify-content: space-evenly

    notion image
    display: flex; justify-content: space-evenly;
    • 요소 사이에 동일한 공간을 만들어 낸다
    notion image

    justify-content: space-around

    notion image
    display: flex; justify-content: space-around;
    • 요소 주변에 동일한 공간을 만들어 낸다
    notion image

    justify-content: space-between

    notion image
    display: flex; justify-content: space-between;
    • 요소들을 양 끝으로 벌린다
    notion image

    5. 요소 흐르기

    flex-wrap: nowrap;

    notion image
    notion image
    notion image
    display: flex; flex-wrap: nowrap;
    • 요소의 공간이 부족하면 축 방향으로 크기가 줄어듬

    flex-wrap: wrap;

    notion image
    notion image
    notion image
    display: flex; flex-wrap: wrap;
    • 요소의 공간이 부족하면 축의 직각 방향으로 요소를 밀어냄

    6. 요소의 크기를 비율로 정하기

    notion image
    .f-box { display: flex; flex-wrap: wrap; } .b1 { flex: 1; } .b2 { flex: 4; } .b3 { flex: 1; } .b4 { flex: 2; }
     
     
    Share article
    Contents
    1. Flex 기본 특징1. 기본 구조2. 축 이동justify-content: startjustify-content: endjustify-content: centeralign-items: startalign-items: centeralign-items: end3. 축 방향 변경flex-direction: rowflex-direction: column4. 공간 만들기justify-content: space-evenlyjustify-content: space-aroundjustify-content: space-between5. 요소 흐르기flex-wrap: nowrap;flex-wrap: wrap;6. 요소의 크기를 비율로 정하기

    jjack1

    RSS·Powered by Inblog