Skip to content

Buzzingz

Unleashing the Power of Code

  • HTML
  • CSS
  • JavaScript
  • Toggle search form

CSS Layout – float and clear

Posted on March 15, 2023March 15, 2023 By shani No Comments on CSS Layout – float and clear
The float property in CSS is used to position an element to the left or right of its container, allowing other content to flow around it. The float property can take two possible values:
  • left: This value positions the element to the left of its container.
  • right: This value positions the element to the right of its container.

Here’s an example of how float can be used to position an image to the right of its containing element:

img {
  float: right;
}

In this example, the float property is set to right, which positions the image to the right of its containing element. This allows any text or other content to flow around the image, rather than being pushed below it.

However, when using float, it’s important to be aware of the clear property. When an element is floated, it can cause other elements to wrap around it, which may not be the desired effect. To prevent this from happening, the clear property can be used to force an element to start on a new line, after all floated elements have been cleared.

The clear property can take three possible values:

  • left: This value clears any floated elements to the left of the current element.
  • right: This value clears any floated elements to the right of the current element.
  • both: This value clears any floated elements to both the left and right of the current element.

Here’s an example of how clear can be used to prevent elements from wrapping around a floated element:

img {
  float: right;
  clear: both;
}

In this example, the float property is set to right, which positions the image to the right of its containing element. The clear property is also set to both, which clears any floated elements to both the left and right of the image, forcing any content to start on a new line.

Overall, the float and clear properties are powerful tools for creating flexible layouts in CSS, but it’s important to use them correctly to avoid unintended effects.

CSS Tags:CSS Layout, CSS Layout - float and clear, Layout

Post navigation

Previous Post: CSS Layout – Overflow
Next Post: CSS Layout – display: inline-block

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

CSS Tutorial

  • Basic CSS Tutorial For Beginners
  • CSS Introduction
  • CSS Syntax
  • CSS Selectors
  • How To Add CSS
  • CSS Comments
  • CSS Colors
  • CSS Backgrounds
  • CSS Borders
  • CSS Margins
  • CSS Margin Collapse
  • CSS Padding
  • CSS Height, Width and Max-width
  • CSS Box Model
  • CSS Outline
  • CSS Text
  • CSS Fonts
  • CSS Web Safe Fonts
  • CSS Font Fallbacks
  • CSS Font Style
  • CSS Font Size
  • CSS Google Fonts
  • CSS Great Font Pairings
  • CSS Icons
  • CSS Links
  • CSS Lists
  • CSS Tables
  • CSS Layout – display: inline-block
  • CSS Layout – float and clear
  • CSS Layout – Horizontal & Vertical Align
  • CSS Layout – Overflow
  • CSS Layout – The display Property
  • CSS Layout – The z-index Property
  • CSS Layout – width and max-width
  • CSS Layout – The position Property
  • CSS Attribute Selectors
  • CSS Image Sprites
  • CSS Image Gallery
  • CSS Dropdowns
  • CSS Horizontal Navigation Bar
  • CSS Vertical Navigation Bar
  • CSS Navigation Bar
  • CSS Opacity / Transparency
  • CSS Pseudo-elements
  • CSS Pseudo-classes
  • CSS Combinators
  • CSS Math Functions
  • CSS The important Rule
  • CSS Specificity
  • CSS Units
  • CSS Website Layout
  • CSS Counters
  • CSS Forms
  • About Us
  • Contact Us
  • Privacy Policy
  • Terms & Conditions

Copyright © 2023 Buzzingz.

Powered by PressBook WordPress theme