Compare with Bootstrap 3, Bootstrap 4 has added many new functions and made some changes. Flex box is one of the new functions.
According to the course instructor, flex box includes a bunch of CSSA properties to move things around the position elements inside of a container instead of a page.
Basically, flex box is a model for positioning content inside a box.
Let's see some flex box examples.
Bootstrap 4 has a new starter template which includes the latest design and development standards. Therefore, I just copy the HTML template on my code editor.
Then, I create two buttons inside a container and add a border to the container. This will help you to see how those buttons move inside the box.
Justify-Content (Move in Row)
To make two buttons move to the left in the flex box, we need to add a property value: "d-flex". It means "display flex", and it will help to set the directions. For the default value, the items are on the left.
The result: the blue and yellow buttons are directed to the left.
If we want to move the buttons from the left to the right or to the center, we only need to add "justify-content-end" (display right) and "justify-content-center"(display center) property value after "d-flex". By the way, "justify-content-start" is displayed to left.
The result:
If you want to have some space between each button, you can set "justify-content-between" and "justify-content around" value.
The result:
Align-Item (Move in Column)
There is not only a left-right direction, but it also has a top-bottom direction. We can also set three common values : "align-items-start" (display top), "align-items-end" (display bottom), and "align-items-center" (display center).The result:
Flex Reverse
If we want the large button moves from the first button to the last button, and the small button moves from the last to the first, we can set "flex-row-reverse" and "flex-column-reverse" value.Flex-row-reverse refers to the items in the box are reversed in a row (left-right). Flex-column-reverse refers to the items in the box are reversed in the column (top-bottom).
The result:
Comments
Post a Comment