Summary
In this lesson, you've learned how the browser places elements on the page and how to change it. You now know that:
- Unless we change it, elements are placed in normal flow: one after another, in the order in which they are in the HTML.
- Block elements (
display: block), such as headings, paragraphs anddiv, start on a new line and are as wide as their parent. When they have a width, we can center them withmargin: 0 auto. - Inline elements (
display: inline), such asstrong,aandspan, sit in a line of text like words. They ignorewidth,heightand top and bottom margins (images are an exception). - Inline-block elements (
display: inline-block) line up in a row like inline elements, but we can size them like blocks. Like text, they are aligned withtext-alignon their parent. display: nonehides an element, and the element takes up no space. With:hover, we can show it only while the mouse pointer is over another element.- The default
positionisstatic: the element stays where normal flow puts it. - The offsets
top,right,bottomandleftmove elements whose position isn'tstatic. Negative values move them the other way. position: relativemoves an element from its original place, which stays reserved for it.position: absolutetakes an element out of normal flow. Its offsets are measured from its nearest ancestor with a position other thanstatic, or, if there's none, from the first screen of the page. Most often, we put it inside a parent withposition: relative.position: fixedworks like absolute, but its offsets are measured from the browser window, so the element doesn't move when you scroll.position: stickykeeps an element in normal flow until scrolling would carry it past the edge given by its offset. Then it sticks to that edge, but only while its parent is on the screen.z-indexdecides which of the overlapping elements with a position is on top: the higher value wins.
Our breed cards stand in a row now, but inline-block gives us little control over them: we can't easily spread them evenly across the row or make them equally tall. In the next lesson, Flexbox, you'll learn the main tool for laying out elements side by side.
Instructions
- 1
Congratulations, you've finished the lesson Display and Position! When you're ready, continue with the next lesson, Flexbox.