0% completed
Float is a CSS property that allows you to take an element out of the normal flow and move it to the left or right side of its container. When an element is floated, other content wraps around it. This property is useful for creating multi-column layouts and aligning images with text.
Floating an element changes how the other elements are arranged. The floated element still remains a part of the document but no longer takes up space in the normal flow, so text and inline elements wrap around it.
Follow the code block below to set the float property in CSS:
/* Float an element to the left */ float: left; /* Float an element to the right */ float: right; /* Remove floating (default behavior) */ float: none;
Explanation:
In this example, we float an image to the left of a paragraph of text. The text flows around the image, creating a classic layout for content with an image.
Explanation:
.float-left
applies float: left
to the image.In this example, we float a block element (a <div>
) to the right within its container. This demonstrates how the content behaves when an element is aligned to the right.
Explanation:
.float-right
applies float: right
, aligning the <div>
to the right..text-content
container wraps around the floated element, demonstrating how floating elements affect content flow.This lesson demonstrates how the float property works by moving elements to the left or right and allowing other content to wrap around them. Understanding float is a key step in building flexible and dynamic web layouts.
.....
.....
.....