whatisthis?

css. FlexBox (display: flex) - (ไธ‹) ๋ณธ๋ฌธ

WEB STUDY/HTML,CSS

css. FlexBox (display: flex) - (ไธ‹)

thisisyjin 2022. 2. 22. 14:05

FlexBox

 

 

css. FlexBox (display: flex) - (ไธŠ)

FlexBox ๐Ÿ’ก key points dispaly: flex ์„ ์–ธ ๊ฐ€๋กœ์ •๋ ฌ? ์„ธ๋กœ์ •๋ ฌ? (flex-direction) ๋ฌด์กฐ๊ฑด ํ•œ์ค„์•ˆ์— ๋‹ค ์ •๋ ฌ? (flex-wrap) ์•„์ดํ…œ ์ •๋ ฌ(align-items, justify-contents) 1 / ํ”Œ๋ ‰์Šค๋ฐ•์Šค ์‚ฌ์šฉ ์„ ์–ธ - ์ •๋ ฌํ•˜๊ณ ์ž ํ•˜..

mywebproject.tistory.com

 

 

 

๐Ÿ’ก key points

 

dispaly: flex ์„ ์–ธ

๊ฐ€๋กœ์ •๋ ฌ? ์„ธ๋กœ์ •๋ ฌ? (flex-direction)

๋ฌด์กฐ๊ฑด ํ•œ์ค„์•ˆ์— ๋‹ค ์ •๋ ฌ? (flex-wrap)

์•„์ดํ…œ ์ •๋ ฌ(align-items, justify-contents)

 

 

 

 


flex๋ฅผ ํ•˜๋ฉด ๋‘๊ฐœ์˜ ์ถ•์ด ์ž๋™์œผ๋กœ ์ƒ๊น€. (๋ˆˆ์— ๋ณด์ด์ง€๋Š” x)

flex-direction์ด ๋ฌด์—‡์ด๋ƒ์— ๋”ฐ๋ผ์„œ ์ถ•์˜ ์œ„์น˜๊ฐ€ ๋‹ฌ๋ผ์ง„๋‹ค.

 

 

 

flex-direction์— ๋”ฐ๋ผ main ์ถ•์ด ์ƒ๊ธฐ๊ณ , (default, ์ฆ‰ row์ผ๋• ์ขŒ์šฐ๋กœ)

main์ถ•์˜ ์ˆ˜์ง์œผ๋กœ cross์ถ•์ด ์ƒ๊ธด๋‹ค.

 

 

main axis๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌํ•˜๋ ค๋ฉด, justify-content

cross axis๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌํ•˜๋ ค๋ฉด, align-items(ํ˜น์€ align-content)

 

 

 

CSS3 - flex (positioning)

https://beautifulcss.com/archives/2812 Beautiful CSS » ํฌ์ง€์…”๋‹ : Flexbox ์ด ๊ฒŒ์‹œ๋ฌผ์€ 2020๋…„ 10์›” 25์ผ ์ˆ˜์ •ํŒ์ž…๋‹ˆ๋‹ค. Image from Introducing Flexbox Fridays ์ด์•ผ๊ธฐ์— ์•ž์„œ Flexbox Layout์€, ์ƒˆ๋กญ๊ฒŒ CS..

mywebproject.tistory.com

 

๐Ÿ“Œ  jusify-content 

- main axis ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌ

flex-start ์•„์ดํ…œ์„ ํ•œ ๋ฉ์–ด๋ฆฌ๋กœ ๋ฌถ์–ด, ์ˆ˜ํ‰๋ฐฉํ–ฅ ์‹œ์ž‘ ์ ์— ์œ„์น˜์‹œํ‚ด
flex-enter ์•„์ดํ…œ์„ ํ•œ ๋ฉ์–ด๋ฆฌ๋กœ ๋ฌถ์–ด, ์ˆ˜ํ‰๋ฐฉํ–ฅ์˜ ๋ ์ ์— ์œ„์น˜์‹œํ‚ด
center ์•„์ดํ…œ์„ ํ•œ ๋ฉ์–ด๋ฆฌ๋กœ ๋ฌถ์–ด, ์ˆ˜ํ‰๋ฐฉํ–ฅ์˜ ์ค‘์•™์— ์œ„์น˜์‹œํ‚ด
space-between ์•„์ดํ…œ์„ ์ปจํ…Œ์ด๋„ˆ์˜ ์–‘์ชฝ ๋์— ๋งž์ถฐ ์ •๋ ฌ
space-around ์ปจํ…Œ์ด๋„ˆ์˜ ์–‘์ชฝ ๋์„ ๊ธฐ์ค€์œผ๋กœ
๊ฐ ์•„์ดํ…œ์˜ ์ „, ํ›„์— ์ผ์ •ํ•œ ๊ฐ„๊ฒฉ์˜ ๊ณต๊ฐ„์„ ๋งŒ๋“ค์–ด ์ •๋ ฌ

 

space-between ๐ŸŸฅ d ๐ŸŸฅ d ๐ŸŸฅ

space-around d ๐ŸŸฅ 2d ๐ŸŸฅ 2d ๐ŸŸฅ d
space-evenly d ๐ŸŸฅ d ๐ŸŸฅ d ๐ŸŸฅ d

 

๐Ÿ“Œ  align-items

- cross axis ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌ

flex-start ์•„์ดํ…œ์„ ํ•œ ๋ฉ์–ด๋ฆฌ๋กœ ๋ฌถ์–ด, ์ˆ˜์ง๋ฐฉํ–ฅ์˜ ์‹œ์ž‘ ์ ์— ์œ„์น˜
flex-enter ์•„์ดํ…œ์„ ํ•œ ๋ฉ์–ด๋ฆฌ๋กœ ๋ฌถ์–ด, ์ˆ˜์ง๋ฐฉํ–ฅ์˜ ๋ ์ ์— ์œ„์น˜
center ์•„์ดํ…œ์„ ํ•œ ๋ฉ์–ด๋ฆฌ๋กœ ๋ฌถ์–ด, ์ˆ˜์ง๋ฐฉํ–ฅ์˜ ์ค‘์•™์— ์œ„์น˜
baseline ์•„์ดํ…œ์„ ์ปจํ…Œ์ด๋„ˆ์˜ baseline์— ๋งž์ถฐ ์ •๋ ฌ
stretch ์ปจํ…Œ์ด๋„ˆ์˜ ์–‘์ชฝ ๋์„ ๊ธฐ์ค€์œผ๋กœ
๊ฐ ์•„์ดํ…œ์˜ ์ „, ํ›„์— ์ผ์ •ํ•œ ๊ฐ„๊ฒฉ์˜ ๊ณต๊ฐ„์„ ๋งŒ๋“ค์–ด ์ •๋ ฌ

 

 

 

+)

๐Ÿ“Œ  align-content

- flex-wrap์„ wrap์œผ๋กœ ์„ค์ •ํ•ด์•ผ ์˜๋ฏธ์žˆ์Œ! (์—ฌ๋Ÿฌ์ค„๋กœ)

 

 

flex-wrap์ด wrap์„ ์‚ฌ์šฉํ•˜๋Š” ์ˆœ๊ฐ„

flex-line์ด ๋‘๊ฐœ ์ƒ๊ธฐ๊ฒŒ ๋จ. (๊ฐ ์ค„๋งˆ๋‹ค)

 

๊ฐ๊ฐ์˜ flex-line์— ํ๋ฅด๋Š” cross axis๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌํ•˜๋ฏ€๋กœ

์•„๋ž˜์™€ ๊ฐ™์ด ์ด์ƒํ•œ ๊ณต๋ฐฑ์ด ์ƒ๊ธด๊ฒƒ์ฒ˜๋Ÿผ ๋ณด์ธ๋‹ค.

 

flex-wrap: wrap ์„ค์ •์‹œ

 

์‚ฌ์‹ค์€ ๊ณต๋ฐฑ์ด ์ƒ๊ธด๊ฒŒ ์•„๋‹ˆ๋ผ flex-line์ด ๋‘๊ฐœ์—ฌ์„œ ์ด๋ ‡๊ฒŒ ๋ณด์ด๋Š”๊ฒƒ.

 

flex-wrap์„ wrap์œผ๋กœ ํ–ˆ์„ ๋•Œ, ๊ฐ flex-line์„ ๊ธฐ์ค€์œผ๋กœ ํ•˜์ง€ ์•Š๊ณ 

content ์ „์ฒด๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌํ•˜๊ณ  ์‹ถ์„๋•Œ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ๋ฐ”๋กœ

align-content ์ด๋‹ค!

 

โ•โ•

align-items์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ center, flex-start, flex-end ๋“ฑ์˜ ๊ฐ’ ์‚ฌ์šฉ ๊ฐ€๋Šฅ.

์ถ”๊ฐ€๋กœ, wrap์„ ํ•ด์„œ ๋‘ ์ค„์ด ๋œ ๊ฒƒ์ด๋ฏ€๋กœ, justify content์—์„œ ์ผ๋˜ ๊ฐ’์ธ

align-content: space-around, space-between, space-evenly๋„ ์‚ฌ์šฉ ๊ฐ€๋Šฅ.

 

 

 

 

align-items - CSS: Cascading Style Sheets | MDN

The CSS align-items property sets the align-self value on all direct children as a group. In Flexbox, it controls the alignment of items on the Cross Axis. In Grid Layout, it controls the alignment of items on the Block Axis within their grid area.

developer.mozilla.org

 

 

๐Ÿ‘ tip

์„  align-items
(ํ•ด๋ณด๊ณ  ๋ญ”๊ฐ€ ์ด์ƒํ•˜๋ฉด)
ํ›„ align-content

 

 


 

๐Ÿ’ก order ์†์„ฑ

 

 

- flex ์‚ฌ์šฉ์‹œ ๋งˆํฌ์—…๊ณผ ์ƒ๊ด€ ์—†์ด css ์ ์šฉ ์ˆœ์„œ ๋ฐ”๊ฟ”๋„ ๋œ๋‹ค!

- order๊ฐ’์„ ์ค˜์„œ ์ˆœ์„œ๋ฅผ ๋ฐ”๊ฟ€ ์ˆ˜ ์žˆ์Œ.

 

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

.child1 {
   order: 2
}

.child2 {
   order: 1
}

.child3 {
   order: 3
}
order CSS ์†์„ฑ์€ ํ”Œ๋ ‰์Šค ๋˜๋Š” ๊ทธ๋ฆฌ๋“œ ์ปจํ…Œ์ด๋„ˆ ์•ˆ์—์„œ ํ˜„์žฌ ์š”์†Œ์˜ ๋ฐฐ์น˜ ์ˆœ์„œ๋ฅผ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.
์ปจํ…Œ์ด๋„ˆ ์•„์ดํ…œ์˜ ์ •๋ ฌ ์ˆœ์„œ๋Š” ์˜ค๋ฆ„์ฐจ์ˆœ order ๊ฐ’์ด๊ณ , ๊ฐ™์€ ๊ฐ’์ผ ๊ฒฝ์šฐ ์†Œ์Šค ์ฝ”๋“œ์˜ ์ˆœ์„œ๋Œ€๋กœ ์ •๋ ฌ๋ฉ๋‹ˆ๋‹ค.

 

 

 

 


 

ref.

 

 

flex - CSS: Cascading Style Sheets | MDN

flex CSS ์†์„ฑ์€ ํ•˜๋‚˜์˜ ํ”Œ๋ ‰์Šค ์•„์ดํ…œ์ด ์ž์‹ ์˜ ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์ฐจ์ง€ํ•˜๋Š” ๊ณต๊ฐ„์— ๋งž์ถ”๊ธฐ ์œ„ํ•ด ํฌ๊ธฐ๋ฅผ ํ‚ค์šฐ๊ฑฐ๋‚˜ ์ค„์ด๋Š” ๋ฐฉ๋ฒ•์„ ์„ค์ •ํ•˜๋Š” ์†์„ฑ์ž…๋‹ˆ๋‹ค.

developer.mozilla.org

 

+) reference lecture

 

๊น€๋ฒ„๊ทธ์˜ HTML&CSS๋Š” ์žฌ๋ฐŒ๋‹ค - ๊ตฌ๋ฆ„EDU

HTML&CSS๋ฅผ ํ•œ๋ฒˆ์—! ํƒ„ํƒ„ํ•œ ๊ฐœ๋…์ดํ•ด๋ถ€ํ„ฐ ์‹ค์Šต๊นŒ์ง€ ํ•œ ๊ฐ•์˜๋กœ ๋๋‚ด๊ธฐ, ์‹ค๋ฌด ๊ฐ€๋Šฅํ•œ ์‹ค๋ ฅ์œผ๋กœ ๐Ÿ˜Ž

edu.goorm.io