mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-04-12 01:00:13 -04:00
fix(curriculum): mismatch in float container collapse example (#63653)
Co-authored-by: Jessica Wilkins <67210629+jdwilkin4@users.noreply.github.com> Co-authored-by: majestic-owl448 <26656284+majestic-owl448@users.noreply.github.com>
This commit is contained in:
@@ -17,7 +17,6 @@ When an element is floated, it's taken out of the normal document flow and pushe
|
||||
<link rel="stylesheet" href="styles.css">
|
||||
<div class="container">
|
||||
<img src="https://placehold.co/150x150" alt="Placeholder Image">
|
||||
<p> This is an example of text flowing around a floated image.</p>
|
||||
</div>
|
||||
```
|
||||
|
||||
@@ -25,7 +24,6 @@ When an element is floated, it's taken out of the normal document flow and pushe
|
||||
.container {
|
||||
border: 1px solid black;
|
||||
padding: 10px;
|
||||
height: 200px;
|
||||
}
|
||||
|
||||
img {
|
||||
@@ -51,6 +49,10 @@ Floats were also popular for creating multi-column layouts before Flexbox and Gr
|
||||
```
|
||||
|
||||
```css
|
||||
.container {
|
||||
border: 1px solid black;
|
||||
}
|
||||
|
||||
/* Clearfix CSS */
|
||||
.container::after {
|
||||
content: "";
|
||||
@@ -71,6 +73,8 @@ img {
|
||||
- `display: block` makes the pseudo-element a block-level element.
|
||||
- `clear: both` ensures the pseudo-element clears both sides of any floated elements above it.
|
||||
|
||||
In the above example, we've added a new paragraph element to make the collapse more noticeable. Because the paragraph remains in the normal document flow, the container expands just enough to wrap around it. Then, we apply the clearfix technique to fix the collapse and make the container's border display correctly. You can try removing the clearfix rule to see the container collapse again.
|
||||
|
||||
The clearfix technique ensures the parent element wraps around its floated children properly. Clearfix forces the parent container to "see" the floated child elements by adding a clear property after the floated content.
|
||||
|
||||
While floats are no longer the go-to method for complex layouts due to more modern techniques like Flexbox and Grid, they still play an essential role in certain scenarios. Whether you're wrapping text around images or working on legacy projects, understanding how floats work and how to clear them properly is key to maintaining well-structured and responsive layouts.
|
||||
|
||||
Reference in New Issue
Block a user