그냥 멋모르고 쓰던 flex 를 실제로 앱 layout에 적용하기 위해서 공부하게 되었다. 선임이 추천한 게임 방식의 튜토리얼 사이트를 통해서 연습해보았다.
결론부터 말하면, 매우 재미있고 알찬 연습 도구이다. 시각적으로 뚜렷하게 보여주니 기억하기도 좋다. 초반에는 '너무 쉽네?' 하다가도 뒤에 가면 금방 까먹고 헤매기도 해서 나중에 복습할 수 있는 짧은 정리 글을 써본다. 프로퍼티 별로 assign할 수 있는 값들, 중간 중간 헷갈리는 부분, 내 스스로 기억하기 좋은 방법/팁을 정리했다.
레벨은 1부터 24까지 나눠져 있고, 개구리를 계속 움직이면서 연습하는 툴이다.
justify-content 프로퍼티를 사용해서 아이템을 horizontally align 한다.
assignable values
#pond {
display: flex;
justify-content: flex-end;
}
align-items 프로퍼티를 사용해서 vertically align 한다.
assignable values
#pond {
display: flex;
align-items: flex-end;
}
#pond {
display: flex;
justify-content: center;
align-items: center;
}
flex-direction이란 프로퍼티를 사용해서 아이템이 컨테이너 안에서 정렬되는 방향을 정의한다.
assignable-items
#pond {
display: flex;
flex-direction: row-reverse;
justify-content: flex-end;
}
Confusing Part
Notice that when you set the direction to a reversed row or column, start and end are also reversed.
Notice that when the flex direction is a column, justify-content changes to the vertical and align-items to the horizontal.
row-reverse, column-reverse 로 부족할 때 order 프로퍼티를 고련한다.
default value는 0. 음수나 양수(-2, -1, 0, 1, 2 ..) 를 부여할 수 있다.
음수가 왼쪽, 양수가 오른쪽.
#pond {
display: flex;
}
.red {
order: -1
}
align-self 프로퍼티는 align-items 의 기능을 아이템 개별적으로 적용할 수 있다. 같은 values 들을 인자로 가진다.
#pond {
display: flex;
align-items: flex-start;
}
.yellow {
align-self: flex-end;
order: 1
}
아이템을 한 줄에 몰아붙일지, 여러 줄로 spread out 할지. assignable values
flex-wrap, flex-direction 을 합친 프로퍼티이다.
how to assign values
#pond {
display: flex;
flex-flow: column wrap
}
여러 줄을 어떻게 배치할지 정하는 프로퍼티.
#pond {
display: flex;
flex-wrap: wrap;
align-content: flex-end;
}