6. (CSS) Flexbox

hyeonn's avatar
Jan 16, 2024
6. (CSS) Flexbox

코드

<!DOCTYPE html> <html> <head> <style> .main { display: flex; justify-content: center; } .flex-container { width: 80%; height: 500px; display: flex; flex-direction: row; justify-content: space-between; align-items: center; background-color: DodgerBlue; } .flex-container>div { background-color: #f1f1f1; margin: 10px; padding: 20px; font-size: 30px; height: 50px; } .a { flex: 1; } .b { flex: 2; } .c { flex: 1; } </style> </head> <body> <div class="main"> <div class="flex-container"> <div class="a">1</div> <div class="b">2</div> <div class="c">3</div> </div> </div> </body> </html>

1. flex는 인라인 블락

  • display: flex; 라고 적는 순간 자식들이 전부 인라인 블락으로 바뀐다.
notion image
notion image
 

2. flex 가운데 배치

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

3. flex-direction

세로 배치
세로 배치
notion image
 

 
flex의 디폴트값은 row
flex의 디폴트값은 row
notion image
 

4. justify-content

  • justify-content는 중심축 정렬. main 액시아스(축) → column으로 하면 세로축을 중심으로 end값을 잡고, → row로 하면 가로축을 중심으로 end를 잡는다.
notion image
notion image
 

 
세로축을 중심으로 end
세로축을 중심으로 end
notion image
 

 
가로축을 중심으로 end
가로축을 중심으로 end
notion image
 

5. flex 화면 비율 1 : 1 : 1

flex: 1; 로 설정하니까 화면 비율이 일정하게 1 : 1 : 1로 설정
flex: 1; 로 설정하니까 화면 비율이 일정하게 1 : 1 : 1로 설정
notion image
 

 
notion image
notion image
 
 
 
Share article

from-web-developer