What it is
Why it matters
As you’ll see, there are many different and overlapping methods for laying out webpages with CSS, such as with floats, positioning, or flexbox. Flexbox is the new standard that is quickly taking over, but Float-based layouts were the most popular for a long time. They are simpler to conceptualize than Flexbox, so we'll start here.
What you'll learn
How floats and clearing work, float based layout, and clear fix techniques.
How to learn it
Specifically, they don’t cover the modern method of clearing floats by using a
.clearfix class, the third method listed in this article. The task below uses
.clearfix, so make sure you know it in addition to the two float clearing methods supplied in the lesson.
- Why does the default behavior of divs limit a site to a single-column layout?
- How can you left align a block element with a fixed width?
- How do you vertically align block elements? What about inline elements?
- What is the “universal truth of CSS layouts”?
- What happens when you float multiple elements in the same direction?
- What happens to the height of a container div when all of its children are floated?
- What is ‘clearing’ a float?
- What property can be used to tell a container div to expand in length to include any of its floated child elements?
- What are two techniques for clearing floats?
- How can we apply a full-bleed background to a centered, fixed width layout?
- What CSS rule can be applied to the .comment class to prevent the text from wrapping under the avatar image in this example?
- What is a
.clearfixclass for? How does it work?
At the bottom of the W3Schools lesson on floats, there’s an example of a simple float-based web layout. I’ve stripped the CSS of it’s layout code in this Pen. Can you add it back to make it look like their example? The menu should be flexible and take up 1/4 of the width of the container. Make sure to bring in the clear fix class from the article above to fix the footer.
Don’t peek at the answer unless you’ve been stuck for a while. Remember, being stuck and trying to figure it out on your own is a much more effective way to learn than reading the solution.
If you’ve finished the Free Code Camp CSS curriculum, you can move on to working on the next section, Applied Visual Design. Don’t worry about finishing it any time soon, because many of the topics, like bezier curves, are esoteric and unnecessary for a beginner.