Parengė: Martynas Kašelionis
From zero to hero
Flexbox - tai efektyvus būdas kuri maketus (angl. layout).
Privalumai:
„Flexbox“ išdėstymas yra tinkamiausias UI komponentams ir nedidelio mastelio maketams, tuo tarpu „Grid“ išdėstymas yra skirtas didesnio mastelio maketams.
display: flex;
apibrėžia flex konteinerį.
Ir įjunia flex rėžimą visiems "child elementams"
.container {
display: flex; flex-direction
.container {
flex-direction: row | row-reverse | column | column-reverse;
}flex-wrap
.container{
flex-wrap: nowrap | wrap | wrap-reverse;
}flex-flow
shorthand'as direction ir wrap
.container{
flex-flow: <‘flex-direction’> || <‘flex-wrap’>
}justify-content
.container {
justify-content: flex-start | flex-end | center | space-between | space-around | space-evenly | start | end | left | right| unsafe;
}align-items
.container {
align-items: stretch | flex-start | flex-end | center | baseline | first baseline | last baseline | start | end | self-start | self-end + ... safe | unsafe;
}align-content
.container {
align-content: flex-start | flex-end | center | space-between | space-around | space-evenly | stretch | start | end | baseline | first baseline | last baseline + ... safe | unsafe;
}order
.item {
order: <integer>; /* default is 0 */
}flex-grow
.item {
flex-grow: <number>; /* default 0 */
}flex-grow
.item {
flex-grow: <number>; /* default 0 */
}flex-shrink
Flex elementui apibrėžiama galimybė susitraukti
.item {
flex-shrink: <number>; /* default 1 */
}flex-basis
Apibrėžia numatytąjį elemento dydį prieš paskirstant likusią vietą.
.item {
flex-basis: <length> | auto; /* default auto */
}flex
Shorthand'as flex-grow, flex-shrink ir flex-basis
.item {
flex: none | [ <'flex-grow'> <'flex-shrink'>? || <'flex-basis'> ]
}align-self
.item {
align-self: auto | flex-start | flex-end | center | baseline | stretch;
}align-self
.item {
align-self: auto | flex-start | flex-end | center | baseline | stretch;
}.parent {
display: flex;
height: 300px;
}
.child {
width: 100px;
height: 100px;
}.flex-container {
/* We first create a flex layout context */
display: flex;
/* Then we define the flow direction
and if we allow the items to wrap
* Remember this is the same as:
* flex-direction: row;
* flex-wrap: wrap;
*/
flex-flow: row wrap;
/* Then we define how is distributed the remaining space */
justify-content: space-around;
}.navigation {
display: flex;
flex-flow: row wrap;
/* This aligns items to the end line on main-axis */
justify-content: flex-end;
}.wrapper {
display: flex;
flex-flow: row wrap;
}
/* We tell all items to be 100% width, via flex-basis */
.wrapper > * {
flex: 1 100%;
}
/* We rely on source order for mobile-first approach
* in this case:
* 1. header
* 2. article
* 3. aside 1
* 4. aside 2
* 5. footer
*/
/* Medium screens */
@media all and (min-width: 600px) {
/* We tell both sidebars to share a row */
.aside { flex: 1 auto; }
}
/* Large screens */
@media all and (min-width: 800px) {
/* We invert order of first sidebar and main
* And tell the main element to take twice as much width as the other two sidebars
*/
.main { flex: 2 0px; }
.aside-1 { order: 1; }
.main { order: 2; }
.aside-2 { order: 3; }
.footer { order: 4; }
}