Flexbox is a set of CSS properties that help make it easy to create more structured layouts with your HTML. Flexbox is very good at putting elements into rows and columns, and centering elements within each other.
Walk through together.
→ Practice using Flexbox
- Create a new HTML and CSS file within your class repo to experiment in.
- Create 4 boxes on the page that are centered horizontally and vertically within the page, and don’t have equal spacing between the boxes.
- Create 2 additional boxes that are aligned to the top right of the page.
- Create 3 additional boxes that are aligned to the bottom of the page and have equal spacing between the boxes.
When you want to move something around on the page, one way to do it is using the position CSS property.
There are 5 primary ways of positioning in CSS.
All elements start out with static positioning by default.
The relative property tells elements that are inside of it to be positioned relative to this element.
The fixed property tells elements to position themselves according to the browser viewport.
The absolute property tells elements to position themselves with the closest parent element that is not using static positioning.
The sticky property tells this element to become fixed when it reaches the top of the viewport.
When using relative, fixed or absolute positioning, you can control which elements come on top of each other using z-index.
Discuss relative width CSS units, e.g. %, vw, vh.
→ Practice using CSS positioning.
- Add several elements to your page using static positioning. Make the elements tall enough so that you can scroll down the page.
- Add at least two additional items to the page that use fixed positioning. Position them in different locations around the page.
- Add an absolutely positioned element to the page.