이 영역을 누르면 첫 페이지로 이동
나눔코딩 블로그의 첫 페이지로 이동

나눔코딩

페이지 맨 위로 올라가기

01. 플렉스 레이아웃 (Flex Layout)

나눔코딩

01. 플렉스 레이아웃 (Flex Layout)

  • 2021.03.21 18:45
  • 05. HTML/css
  OS   Windows 10 PRO 64bit 버전 20H2 (OS 빌드 19042.867)
  CSS   3
깃헙 주소

 

 

sout1217/TIL2021

Contribute to sout1217/TIL2021 development by creating an account on GitHub.

github.com

 

Flex Layout
  • Container
    •  display
    •  justify-content
    •  align-items
    •  flex-wrap
    •  flex-direction
    •  flex-flow (flex-wrap + flex-direction)
    •  align-content (default stretch)
  • Item
    •  flex-grow
    •  order
    •  flex-shrink
    •  align-self

 

📌 Container

default

.container { } .item { }

[코드보기]

더보기
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>플렉스 레이아웃</title>
<style>
body {
margin: 0;
}
.t1 {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.t1:after {
content: attr(data-value);
}
.t2 {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.t2:after {
content: attr(data-value);
}
.containerWrap {
position: relative;
display: block;
}
.container {
border: 1px red dashed;
height: 50vh;
background: #eeef85;
box-sizing: border-box;
}
.item {
width: 40px;
height: 40px;
border: 1px solid;
}
.item1, .item11 {
background: #9bff31;
}
.item2, .item12 {
background: #e8c453;
}
.item3, .item13{
background: #31ff7d;
}
.item4, .item14 {
background: #31ffbe;
}
.item5, .item15{
background: #3195ff;
}
.item6, .item16 {
background: #fffc31;
}
.item7, .item17{
background: #8031ff;
}
.item8, .item18{
background: #ff31b3;
}
.item9, .item19 {
background: #ff3131;
}
.item10, .item20 {
background: #3153ff;
}
</style>
</head>
<body>
<div class="parent">
<div class="t1" data-value="Flex Box 1"></div>
<div class="container">
<div class="item item1">1</div>
<div class="item item2">2</div>
<div class="item item3">3</div>
<div class="item item4">4</div>
<div class="item item5">5</div>
<div class="item item6">6</div>
<div class="item item7">7</div>
<div class="item item8">8</div>
<div class="item item9">9</div>
<div class="item item10">10</div>
</div>
</div>
<div class="parent">
<div class="t2" data-value="Flex Box 2"></div>
<div class="container">
<div class="item item11">11</div>
<div class="item item12">12</div>
<div class="item item13">13</div>
<div class="item item14">14</div>
<div class="item item15">15</div>
<div class="item item16">16</div>
<div class="item item17">17</div>
<div class="item item18">18</div>
<div class="item item19">19</div>
<div class="item item20">20</div>
</div>
</div>
</body>
</html>


flex

.container { display: flex; }

 

justify-cotent

  • flex-start

.container { display: flex; justify-content: flex-start; }

 

  • center

.container { display: flex; justify-content: center; }

 

  • flex-end

.container { display: flex; justify-content: flex-end; }

 

  • space-evenly

.container { display: flex; justify-content: space-evenly; }

 

  • space-around

.container { display: flex; justify-content: space-around; }

 

  • space-between

.container { display: flex; justify-content: space-between; }

 

align-items

 

  • flex-start

.container { display: flex; align-items: flex-start; }

 

  • center

.container { display: flex; align-items: center; }

 

  • flex-end

.container { display: flex; align-items: flex-end; }

 

  • baseline

.container { display: flex; align-items: baseline; } .item1 { width: 100px; height: 100px; line-height: 100px; text-align: center; }

 

  • stretch (default)

.container { display: flex; align-items: stretch; } .item { /*height: 40px;*/ width: 40px; border: 1px solid; }

 

justify-content & align-items

 

flex-wrap

⚠ item 들이 container 의 넓이를 벗어나는 경우

 

 

  • nowrap (default)

.container { display: flex; flex-wrap: nowrap; }

 

  • wrap

.container { display: flex; flex-wrap: wrap; }

 

  • wrap-reverse

.container { display: flex; flex-wrap: wrap-reverse; }

 

flex-direction

  • row (default)

.container { display: flex; flex-direction: row; }

 

  • row-reverse

.container { display: flex; flex-direction: row-reverse; }

 

  • column

.container { display: flex; flex-direction: column; }

 

  • column-reverse

.container { display: flex; flex-direction: column-reverse; }

 

flex-direction: column & justify-content

  • column
  • flex-start

.container { display: flex; flex-direction: column; justify-content: flex-start; }

 

  • column
  • center

.container { display: flex; flex-direction: column; justify-content: center; }

 

  • column
  • flex-end

.container { display: flex; flex-direction: column; justify-content: flex-end; }

 

  • column
  • space-evenly

.container { display: flex; flex-direction: column; justify-content: space-evenly; }

 

  • column
  • space-evenly

.container { display: flex; flex-direction: column; justify-content: space-around; }

 

  • column
  • space-between

.container { display: flex; flex-direction: column; justify-content: space-between; }

 

flex-direction: column & align-items

  • column
  • flex-start

.container { display: flex; flex-direction: column; align-items: flex-start; }

 

  • column
  • center

.container { display: flex; flex-direction: column; align-items: center; }

 

  • column
  • flex-end

.container { display: flex; flex-direction: column; align-items: flex-end; }

 

flex-direction: column & align-items & justify-content

 

align-content

  • stretch (default)

.container { display: flex; flex-wrap: wrap; align-content: stretch; } .item { width: 100%; }

 

  • flex-start

.container { display: flex; flex-wrap: wrap; align-content: flex-start; } .item { width: 100%; }

 

  • center

.container { display: flex; flex-wrap: wrap; align-content: center; } .item { width: 100%; }

 

  • flex-end

.container { display: flex; flex-wrap: wrap; align-content: flex-end; } .item { width: 100%; }

 

  • space-evenly

.container { display: flex; flex-wrap: wrap; align-content: space-evenly; } .item { width: 100%; }

 

  • space-around

.container { display: flex; flex-wrap: wrap; align-content: space-around; } .item { width: 100%; }

 

  • space-between

.container { display: flex; flex-wrap: wrap; align-content: space-between; } .item { width: 100%; }

 

inline-flex

  • containerWrap : block
  • container : inline-flex

.containerWrap { display: block; } .container { display: flex; flex-direction: column; align-items: flex-end; }

 

  • containerWrap : inline-block
  • container : inline-flex

.containerWrap { display: inline-block; } .container { display: flex; flex-direction: column; align-items: flex-end; }

 

  • 💥 container n개 의 넓이의 합이 containerWrap 의 넓이 보다 큰 경우 자동으로 block 처리 된다
  • 💥 만약 container 1개의 넓이가 containerWrap 넓이보다 큰 경우 가로 스크롤이 생긴다
  • containerWrap : inline-block
  • container : inline-flex

 

.containerWrap { display: inline-block; } .container { display: flex; flex-direction: column; align-items: flex-end; }

더보기

📌 Item

  • flex-grow = flex

.item { flex-grow: 1; }

 

.item1 { flex-grow: 1; }

 

.item1, .item10 { flex-grow: 1; }

 

container - flex-wrap: wrap & item - flex-grow: 1

.item { width: 40px; flex-grow: 1; }

 

.item { width: 80px; flex-grow: 1; }

 

.item { width: 750px; flex-grow: 1; }

 

order

  • order: 0 (default)

.item1 { order: 0 }

 

  • order: 1

.item1 { order: 1 }

 

  • order: 1
  • order: -1

.item1 { order: 1 } .item3 { order: -1 }

 

flex-shrink

  • flex-shrink: 1 (default) 

.item5 { flex-shrink: 1; }

 

  • flex-shrink: 0 

.item5 { flex-shrink: 10; }

 

  • flex-shrink: 10 

.item5 { flex-shrink: 0; }

 

align-self

  • flex-start (default)

.item2 { align-self: flex-start; }

 

  • center

.item2 { align-self: center; }

 

  • flex-end

.item2 { align-self: flex-end; }

 

  • baseline

.container { display: flex; align-items: stretch; } .item { line-height: 25vw; } .item2 { align-self: baseline; }

이 글은 (새창열림) 본 저작자 표시 규칙 하에 배포할 수 있습니다. 자세한 내용은 Creative Commons 라이선스를 확인하세요.
Creative Commons
본 저작자 표시

'05. HTML > css' 카테고리의 다른 글

06. CSS - 아래 테두리 주기 border-bottom hover  (0) 2021.09.10
05. CSS - 리스트 링크 (list-item link)  (0) 2021.09.10
04. CSS - 버튼 누름 표시  (0) 2021.09.10
03. CSS - 모달창(다이얼로그창) 만들기  (0) 2021.09.10
02. 백그라운드 blur 주기  (0) 2021.08.08

댓글

댓글을 사용할 수 없습니다.

이 글 공유하기

  • 구독하기

    구독하기

  • 카카오톡

    카카오톡

  • 트위터

    트위터

  • Facebook

    Facebook

  • 카카오스토리

    카카오스토리

  • 밴드

    밴드

  • 네이버 블로그

    네이버 블로그

  • Pocket

    Pocket

  • Evernote

    Evernote

다른 글

  • 05. CSS - 리스트 링크 (list-item link)

    05. CSS - 리스트 링크 (list-item link)

    2021.09.10
  • 04. CSS - 버튼 누름 표시

    04. CSS - 버튼 누름 표시

    2021.09.10
  • 03. CSS - 모달창(다이얼로그창) 만들기

    03. CSS - 모달창(다이얼로그창) 만들기

    2021.09.10
  • 02. 백그라운드 blur 주기

    02. 백그라운드 blur 주기

    2021.08.08
다른 글 더 둘러보기

정보

나눔코딩 블로그의 첫 페이지로 이동

나눔코딩

  • 나눔코딩의 첫 페이지로 이동

검색

메뉴

  • 홈
  • 태그
  • 방명록

카테고리

  • 분류 전체보기 (316)
    • ∞. 읽은 거리 (3)
    • ∞. 기술 면접 (61)
      • 1. 자료구조 (0)
      • 2. 네트워크 (9)
      • 3. 운영체제 (11)
      • 4. 데이터베이스 (13)
      • 5. 디자인 패턴 (0)
      • 6. 알고리즘 (0)
      • 7. 자바 (15)
      • 8. 자바스크립트 (7)
      • 9. 스프링 (5)
      • 10. 시큐리티 (1)
      • 11. 기타 (0)
      • 12. Vue (0)
    • ∞. 웹개발 유용한 사이트 (14)
    • ∞. 트러블 슈팅 + TIL (7)
    • 00. 출발 (9)
    • 01. 엑셀 (9)
      • 기초 (4)
      • 컴활 1급 (4)
      • VBA (0)
    • 02. 엑세스 (9)
      • 기초 (5)
      • 컴활 1급 (4)
    • 04. Oracle (1)
      • 기초 (1)
    • 03. JAVA (8)
      • 기초 (7)
      • 객체지향 프로그래밍 (0)
    • 05. HTML (13)
      • 기초 (1)
      • css (10)
      • sass (0)
      • less (0)
    • 06. Javascript (16)
      • 기초 (13)
      • ES6 모듈 (2)
      • Canvas (0)
    • 07. JSP (0)
      • 기초 (0)
    • 08. jQuery (0)
      • 기초 (0)
    • 09. BootStrap (1)
      • 기초 (0)
      • v4 - Layout (1)
    • 10. Spring (30)
      • 기초 (3)
      • 실험 (4)
      • MVC (1)
      • BOOT (6)
      • Security (10)
      • Lib (Library) (2)
      • 벤치마킹 (0)
      • JUnit5 (2)
      • DevTools (0)
      • Socket (1)
      • Batch (0)
      • Mobile (0)
      • WebFlux (0)
      • Cloud (0)
      • Thymleaf (0)
      • Actuator (0)
      • 성능 테스트 (1)
    • 11. JetBrains (34)
      • 기초 (1)
      • IntelliJ IDEA (33)
      • WebStorm (0)
      • Pycham (0)
    • 12. API (0)
      • 기초 (0)
      • 네이버 API (0)
      • 카카오 API (0)
      • 구글 API (0)
      • 인스타그램 API (0)
    • 13. AutoHotkey (1)
    • 14. Python (8)
      • 기초 (3)
      • Selenium (2)
      • Beautiful Soup (0)
      • openpyxl (1)
      • Pyqt5 (0)
      • Deep learning (open CV) (0)
      • Geocoder (0)
      • Anaconda (0)
      • DeepLearning (0)
      • Jupyter Nootbook (0)
    • 14.5. R (0)
    • 15. JMeter (0)
      • 다운로드 (0)
    • 16. Vue JS (23)
      • 기초 (3)
      • Vue 2 (15)
      • Vue 3 (5)
      • Vuetify 2.5.8 (0)
    • 17. Git (12)
      • 기초 (8)
      • ItelliJ IDEA (4)
      • SourceTree (0)
    • 18. AWS (5)
      • 기초 (2)
      • Jira (3)
    • 19. Naver Cloud Platform (0)
    • 20. Google Cloud Platform (0)
      • 기초 (0)
      • stt & tts (0)
    • 21. Kotlin (0)
    • 22. Android (0)
      • 기초 (0)
      • Java (0)
      • Kotlin (0)
      • Flutter FrameWork (0)
    • 23. Clean Code [JAVA] (1)
    • 24. BuildTool (1)
      • Maven (1)
      • Gradle (0)
    • 25. 자료 구조와 알고리즘 (18)
      • JAVA (1)
      • Java Script (1)
      • 프로그래머스 (0)
      • 백준 알고리즘 (0)
      • 나의 알고리즘 (14)
      • Brilliant 공부 (0)
    • 26. React (1)
      • 기초 (0)
      • 강의 정리 (1)
    • 27. PostMan (0)
      • 기초 (0)
    • 28. 프로그래머스 (9)
    • 29. Leet Code (0)
    • 30. MySQL (3)
      • 기초 (2)
      • 문제 (1)
    • 73. GraphQL (0)
    • 74. Nuxt JS (0)
    • 75. Electron (0)
    • 76. UX &amp; UI Design Tool (0)
      • 기초 (0)
      • Axure (0)
      • Sketch (0)
      • Figma (0)
    • 77. MarkDown (1)
      • 기초 (1)
    • 78. Tomcat (1)
      • 메모 (1)
    • 79. Element JS (0)
    • 80. Parallax JS (0)
      • 기초 (0)
    • 81. Player JS (0)
      • 기초 (0)
    • 82. Smart Maker (0)
    • 83. Vim (0)
      • 기초 (0)
    • 84. Linux (0)
      • 기초 (0)
      • Centos 7 (0)
      • Ubuntu (0)
    • 85. Node JS (2)
      • 기초 (1)
      • WebRTC (0)
      • NVM (1)
    • 86. Propeller JS (0)
    • 87. FullPage JS (0)
      • 기초 (0)
    • 88. 아두이노 (0)
    • 89. Tensorflow (0)
    • 90. 웹 패킷 분석 (0)
    • 91. 크롬 개발자도구 (0)
    • 92. 디자인 패턴 (7)
      • 생성(Creational) (3)
      • 구조(Structral) (1)
      • 행위(Behavioral) (2)
      • SOLID 패턴 (0)
    • 95. Linux Shell Script (0)
    • 96. 구글 애널리스틱 (0)
    • 97. ffmpeg (0)
    • 98. ShareX (1)
    • 자료실 (0)
    • 기타 (2)

인기 글

공지사항

태그

  • 엑셀 기타작업
  • 졵
  • 엑셀 분석작업
  • 엑셀 기본작업
  • 깁
  • 엑셀 글씨
  • 엑셀 가운데맞춤
  • 엑셀 표시형식

나의 외부 링크

  • 비전공자 개발자
  • 자바 디자인 패턴
  • 자바 디자인 패턴
  • 스프링 블로그
  • 해킹보안 & 웹 관련
  • ERD 생성
  • 전문 기술 블로그
  • Servlet에 대한 개념없이 스프링을 했네요?
  • 스프링 FitlerChainList
  • 알고리즘 파워 블로그

정보

THE HEYDAZE의 나눔코딩

나눔코딩

THE HEYDAZE

블로그 구독하기

  • 구독하기
  • RSS 피드

방문자

  • 전체 방문자
  • 오늘
  • 어제

티스토리

  • 티스토리 홈
  • 이 블로그 관리하기
  • 글쓰기
Powered by Tistory / Kakao. © THE HEYDAZE. Designed by Fraccino.

티스토리툴바

개인정보

  • 티스토리 홈
  • 포럼
  • 로그인

단축키

내 블로그

내 블로그 - 관리자 홈 전환
Q
Q
새 글 쓰기
W
W

블로그 게시글

글 수정 (권한 있는 경우)
E
E
댓글 영역으로 이동
C
C

모든 영역

이 페이지의 URL 복사
S
S
맨 위로 이동
T
T
티스토리 홈 이동
H
H
단축키 안내
Shift + /
⇧ + /

* 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.