diff --git a/html/lesson4/assets/images/align-items.svg b/html/lesson4/assets/images/align-items.svg new file mode 100644 index 00000000..c93dc3e1 --- /dev/null +++ b/html/lesson4/assets/images/align-items.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/html/lesson4/assets/images/align-self.svg b/html/lesson4/assets/images/align-self.svg new file mode 100644 index 00000000..ef97f036 --- /dev/null +++ b/html/lesson4/assets/images/align-self.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/html/lesson4/assets/images/flex-container.svg b/html/lesson4/assets/images/flex-container.svg new file mode 100644 index 00000000..dfc74319 --- /dev/null +++ b/html/lesson4/assets/images/flex-container.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/html/lesson4/assets/images/flex-direction.svg b/html/lesson4/assets/images/flex-direction.svg new file mode 100644 index 00000000..8faa6d0d --- /dev/null +++ b/html/lesson4/assets/images/flex-direction.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/html/lesson4/assets/images/flex-grow.svg b/html/lesson4/assets/images/flex-grow.svg new file mode 100644 index 00000000..d328b0e4 --- /dev/null +++ b/html/lesson4/assets/images/flex-grow.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/html/lesson4/assets/images/flex-items.svg b/html/lesson4/assets/images/flex-items.svg new file mode 100644 index 00000000..89373923 --- /dev/null +++ b/html/lesson4/assets/images/flex-items.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/html/lesson4/assets/images/flex-order.svg b/html/lesson4/assets/images/flex-order.svg new file mode 100644 index 00000000..92f2fcec --- /dev/null +++ b/html/lesson4/assets/images/flex-order.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/html/lesson4/assets/images/justify-content.jpeg b/html/lesson4/assets/images/justify-content.jpeg new file mode 100644 index 00000000..3a75e42f Binary files /dev/null and b/html/lesson4/assets/images/justify-content.jpeg differ diff --git a/html/lesson4/tutorial.md b/html/lesson4/tutorial.md index 80ffdc54..397b7897 100644 --- a/html/lesson4/tutorial.md +++ b/html/lesson4/tutorial.md @@ -12,7 +12,7 @@ Today we will be building a website and learning more about CSS layouts and form ### Goal -The page we will build will look similar to this [example page]( https://tutorials.codebar.io/html/lesson4/example.html "Grace Hopper") +The page we will build will look similar to this [example page](https://tutorials.codebar.io/html/lesson4/example.html "Grace Hopper") ### Required files @@ -350,6 +350,232 @@ Add space around the images so there is some separation between them and the tex } ``` +## Flexible Box Layout + +It is a CSS module that defines a set of properties for positioning, aligning, and distributing space between elements in a container, even if their size is unknown or dynamic. + +The basic idea is to separate items into a block container (`flex container`) and its children (`flex items`). + + + + + +A Flexbox container can change the width and height of its children, as well as the direction of their arrangement - alignment in a column or line, the order in which elements are displayed and the distance between them. A container expands elements to best fit the available space, or shrinks them to prevent overflow. + +> In a flex container, most of the rules for arranging elements according to their type and document flow are overridden. + +> Elements lose their "type", stop being inline or block. +> Block elements no longer go vertically under each other. +> Margins at the junction with the border of the parent do not fall out. +> Elements' vertical padding does not collapse. +> Automatic vertical indents work. + +### Terminology + +The normal order of elements is determined by the document flow and their type (block or inline). In the Flexbox model, the direction in which items are laid out is determined by the direction axes of the container, along which the items line up. + +- **main axis** - the main axis of the flex container, along which the elements are located. It doesn't have to be horizontal, its direction is controlled by the `flex-direction` property. +- **main-start** and main-end - elements in a container are always located from `main-start` (the start of the main axis) to `main-end` (the end of the main axis). +- **cross axis** - the cross axis, which is always perpendicular to the main axis. Its direction depends on the main axis and is not explicitly set. +- **cross-start** and cross-end - the beginning and end of the transverse axis along which the lines of the element are located + +### Container Properties + +A flex `container` is the parent of a group of elements that need to be reordered. It is the container properties that control the direction of the axes, multiline and positioning of elements in the line. + + + +#### `display` property + +```css +display: flex | inline-flex; +``` + +Creates a flex container, block or inline-block, depending on the given value, and sets the flex context for all children (not descendants) of the container, turning them into flex items. + +```html +
+``` + +Let's create a horizontal menu by turning `ul.menu` into a flex container. Then its children, `li.item` elements, will be located along the main axis, which by default goes from left to right. + +```css +.menu { + display: flex; +} +``` + +The flex container `ul.menu` has no effect on `a.link` inside the list items, because they are its children, not children. It is the children that become flex items, in our case, the `li.item` elements. + +#### `flex-direction` property + +Flexbox is a system for laying out elements in one specific direction - either horizontally or vertically. The `flex-direction` property sets the direction of the main axis, defining the direction of the elements in the container. + +```css +flex-direction: row | row-reverse | column | column-reverse; +``` + +- `row` - the axis starts on the left and ends on the right. This is the default value. +- `row-reverse` - the axis starts on the right and ends on the left. +- `column` - the main axis becomes vertical, starting at the top and ending at the bottom. +- `column-reverse` - the main axis becomes vertical, starting at the bottom and ending at the top. + +  + +By default, `flex-direction` is set to `row`, so the top menu items start lining up from left to right. The bottom menu is set to `row-reverse`, the main axis is reversed 180 degrees, and the items line up from right to left. + +#### `justify-content` property + +Controls the positioning of elements on the main axis, from `main-start` to `main-end`. + +```css +justify-content: flex-start | flex-end | center | space-between | space-around | + space-evenly; +``` + +- `flex-start` - items are pressed to the start of the axis. This is the default value. +- `flex-end` - elements are pressed to the end of the axis. +- `center` - elements are centered on the axis. +- `space-between` - elements are evenly distributed on the main axis. The first element is set to the beginning of the axis, and the last element to the end. +- `space-around` - elements are distributed evenly, but the left and right elements lag behind the container borders by half the gap between the other elements. +- `space-evenly` - the elements are distributed so that the distance between the elements, and from the outermost elements to the borders of the container, is the same + +  + +The most commonly used values, including the default value, are shown in the example. These include shifting content to the right (`flex-end`), centering (`center`), and evenly distributing space between elements (`space-between`). + +#### `align-items` property + +Controls the arrangement of elements along the transverse axis. This is the equivalent of `justify-content` for the main axis. + +```css +align-items: stretch | flex-start | flex-end | center | baseline; +``` + +- `stretch` - elements are stretched to the full length of the axis. This is the default value. +- `flex-start` - elements are pressed to the start of the axis. +- `flex-end` - elements are pressed against the end of the axis. +- `center` - elements are centered on the axis. +- `baseline` - elements are aligned to the baseline of their text content. + + + +Probably the most common use is to vertically center elements in a row, especially if the elements are of different heights. Let's add a header with a logo to our markup and nest the menu in the header so that the logo and the menu are neighbors. + +```html +