DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Modify JSON Data in Postgres and Hibernate 6
  • Top 10 C# Keywords and Features
  • New ORM Framework for Kotlin
  • Red-Black Trees in C#: A Guide to Efficient Self-Balancing Binary Search Trees

Trending

  • Why Role-Based Access Control Fails for AI Agents — and How to Fix It With Memory Lineage Engines
  • Designing Frontend Applications for Failure, Not Just Success
  • Moving 900+ GB of Prometheus Without a Cutover Weekend
  • Treat Salesforce Configuration Like Code: Release Discipline in a Copado Pipeline

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Data Engineering
  3. Data
  4. CSS Clear Float

CSS Clear Float

Clearly, this post is going to float your boat. But, bad puns aside, this is a great introduction to an interesting and useful CSS property.

By 
Tatjana Boskovic
·
Mar. 28, 18 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
28.4K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

A little while ago we wrote about the float property. So, now is a good time to explain the clear property.

The clear property is directly related to the float property. It specifies if an element should be next to the floated elements or if it should move below them. This property applies to both floated and non-floated elements.

If an element can fit in the horizontal space next to the floated elements, it will;unless you apply the clear property to that element in the same direction as the float. Then the element will move below the floated elements.

Every element created in CSS needs to have the quality design added.

The clear property can have following values:

  • None - the element is not moved down to clear past floats.
  • Left - the element is moved down to clear past left floats.
  • Right - the element is moved down to clear past right floats.
  • Both - the element is moved down to clear past both left and right floats.

Support

After consulting the Can I Use service, we see that the support is over 87%.

Examples

HTML

<div class=”container”>
  <div class=”left-segment”></div>
  <div class=”left-segment”></div>
  <p class=”text-clear”>Cardigan aesthetic direct trade, migas locavore shoreditch DIY bicycle rights lyft street art bitters.</p>
</div>

CSS

.container {
  border: solid thin #ccc;
}

.left-segment {
  float: left;
  background-color: #C98EED;
  height: 200px;
  width: 200px;
  margin-right: 10px;
}

.text-clear {
  clear: left;
}

Here we can see divs that have float: left applied to them. After we have set clear: left to the text paragraph, it moved below the floated elements.

HTML

<div class=”container”>
  <div class=”right-segment”></div>
  <div class=”right-segment”></div>
  <p class=”text-clear”>Cardigan aesthetic direct trade, migas locavore shoreditch DIY bicycle rights lyft street art bitters.</p>
</div>

CSS

.container {
  border: solid thin #ccc;
}

.right-segment {
  float: right;
  background-color: #8FC9FF;
  height: 200px;
  width: 200px;
  margin-left: 10px;
}

.text-clear {
  clear: right;
}

Next, we see two divs with the float: right property and a paragraph with the clear: right property. By setting this, the paragraph gets moved below the floated elements.

Now is a good time to add some formatting to the text.

HTML

<div class=”container”>
  <div class=”left-segment”></div>
  <div class=”right-segment”></div>
  <p class=”text-clear”>Cardigan aesthetic direct trade, migas locavore shoreditch DIY bicycle rights lyft street art bitters.</p>
</div>

CSS

.container {
  border: solid thin #ccc;
}

.left-segment {
  float: left;
  background-color: #8FC9FF;
  height: 200px;
  width: 200px;
}

.right-segment {
  float: right;
  background-color: #8FC9FF;
  height: 200px;
  width: 200px;
}

.text-clear {
  clear: both;
}

Finally, the last example shows the usage of the clear: both property. The two divs are floated left and right, while the paragraph has the clear property added to it. With this, it gets moved below both of the floated elements. It's good to mention that this is the most commonly used clear property.

Summary

Hope this article will help you in your projects. Be careful when using this property, it is known to have caused a lot of confusion in the past. But, we are sure that after reading this article, you are good to go!

Happy coding!

CSS Clear (Unix) Data Types Element Property (programming)

Published at DZone with permission of Tatjana Boskovic. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Modify JSON Data in Postgres and Hibernate 6
  • Top 10 C# Keywords and Features
  • New ORM Framework for Kotlin
  • Red-Black Trees in C#: A Guide to Efficient Self-Balancing Binary Search Trees

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook