캐러셀을 구현하면서 캐러셀 안에 들어가는 카드의 너비가 의도와 다르게 설정되는 문제가 있었다. 삽질과 ChatGPT의 도움으로 해당 문제는 flex와 관련이 있고, 그중 flex-basis에 대한 이해가 부족하다는 것을 알게 되었다. 이번 기회에 flex-basis를 비롯하여 flex-grow, flex-shrink도 함께 정리해 보았다.
flex container의 남은 공간의 할당 비율이다.
flex item들의 크기의 합이 flex container보다 클 경우, flex item의 축소 비율이다. 즉, 값이 클수록 flex item의 크기가 더 많이 줄어든다.
flex item의 초기 크기이다. 3가지의 특징이 있다.
flex-direction: row
일 경우 width, flex-direction: column
일 경우 height를 의미한다.flex-basis: auto
일 경우에는 width/height가 적용된다.아래처럼 축약하여 쓸 수 있다.
flex: flex-grow flex-shrink flex-basis
🔗 https://developer.mozilla.org/en-US/docs/Web/CSS/flex-basis
🔗 https://velog.io/@jiseong/CSS-flex-basis%EC%99%80-width#5-flex-basis-width-flex-shrink-1
🔗 https://blogpack.tistory.com/863