FLEXB X
![](https://s3.amazonaws.com/media-p.slid.es/uploads/537536/images/2874544/original_2db55ab3-3fe8-4a5b-b96f-0e3eaeb35843_BlackBoxCAD.png)
COMP 126: Practical Web Design & Development for Everyone
INTRODUCTION TO
basic units: flex-container, flex-item
![](https://s3.amazonaws.com/media-p.slid.es/uploads/581429/images/5366769/Screen_Shot_2018-10-15_at_3.24.52_PM.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/581429/images/5366772/Screen_Shot_2018-10-15_at_3.24.59_PM.png)
1. turn a container into a Flex container with the display property
.container {
display: flex;
2. Main axis/flex direction?
![](https://s3.amazonaws.com/media-p.slid.es/uploads/581429/images/9826556/HHwxqz2N4bNksz9YwcMBAtD0z9TTCxeNXNBS.png)
3. ADD FLEX ITEMS
<div class="container">
<div class="item1">item one</div>
<div class="item1">item two</div>
<div class="item1">item three</div>
</div>
Now The child elements are flex-items and ready for flexbox!
with/out flexbox
display: inline-flex
PROPERTIES for flex-container
-
display (flex or inline-flex)
-
flex-direction (sets main axis)
-
flex-wrap (do items wrap from line to line inside container or just shrink/expand?)
-
flex-flow (shorthand for flex-direction and flex-wrap)
-
justify-content (aligns items along main axis)
-
align-items (aligns items along cross axis)
-
align-content (aligns multiple lines of items along cross axis)
-
gap, row-gap, column-gap (adds gaps between flex items)
These properties can only be applied to a container element to which you've applied display: flex; or display: inline-flex;
Justify-content: aligns flex-items along the main axis
Used primarily when the flex-items' sizes are fixed or at their max-height/max-width
ALIGN-ITEMS: ALIGNS ITEMS on CROSS AXIS
ALIGN-Content: aligns lines of items in cross axis
flex-wrap: whether flex-items wrap from line to line in a flex-container
Flex-item properties
- order: affects the order in which single items appear in a flex container
- align-self: overrides the default or assigned (with align-items) alignment for an individual item in a flex container
- flex-grow: how much should a flex item grow/what proportion of the available space should it take up, if space is available?
- flex-shrink: how much/by what proportion can a flex item shrink if necessary?
- flex-basis: default size of a flex item before any growing or shrinking or redistribution of available space in a flex container
NOTE: these properties can only be applied to individual items within a flex-container
ALIGN-SELF: OVERRIDES DEFAULT OR ALIGN-ITEMS ALIGNMENT FOR INDIVIDUAL FLEX-ITEMS
Order: alters items' order & flex-grow: how much flex items expand when there's room
Flex-shrink: how much flex items shrink if constrained
Flex-basis: default size of flex-items before space is distributed
Flex: shorthand for grow, shrink, basis
![](https://s3.amazonaws.com/media-p.slid.es/uploads/581429/images/9826633/Screen_Shot_2022-09-08_at_12.09.07_PM.png)
https://codepen.io/tkjn/pen/yLwWQav?editors=1100
stuff you can do with flexbox
center items in a container
distribute items equally
responsive navigation
responsive layout
flexbox LAYOUT demo
using flex:
126-Flexbox
By tkjn
126-Flexbox
- 6,816