Questions tagged [clearfix]

A clearfix is a way for an element to automatically clear after itself, so that you don't need to add additional markup. It's generally used in float layouts where elements are floated to be stacked horizontally.

Description

A clearfix is a way for an element to automatically clear after itself, so that you don't need to add additional markup. It's generally used in float layouts where elements are floated to be stacked horizontally.

The clearfix is a way to combat the zero-height container problem for floated elements.


Examples

.clearfix:after {
    content: " ";
    display: block;
    clear: both;
    visibility: hidden;
    line-height: 0;
    height: 0;
}

Normally you would need to do something as follows:

<div style="float: left;">Sidebar</div>
<div style="clear: both;"></div> <!-- Clear the float -->

With clearfix, you only need to

<div style="float: left;" class="clearfix">Sidebar</div>
<!-- No Clearing div! -->

References

  1. StackOverflow - What is clearfix?
  2. Article by Chris Coyer @ CSS-Tricks
  3. A new micro clearfix hack
  4. An Overview of Different clearfix Methods
230 questions
1
vote
0 answers

Yii2 clearfix.less not populating in production environment

I designed a website using Yii2, and while I have done many, this problem only appears on one of them due to some reason that I cannot determine. The views from dektrium\yii2-user extension show up fine on my development environment, but are messed…
Shahid Thaika
  • 2,133
  • 5
  • 23
  • 59
1
vote
1 answer

CSS floating element break to next line

I've come to the condition like this: HTML
Lorem ipsum dolor sit amet, consectetur adipisicing elit
Lorem ipsum dolor sit amet, consectetur adipisicing elit
Ashish
  • 313
  • 1
  • 5
  • 14
1
vote
1 answer

Is it safe to update ::before and ::after clearfix to a simple ::after one?

At present, a framework I work with utilises the classic clearfix: @mixin clearfix { zoom: 1; &::before, &::after { content: ''; display: table; } &::after { clear: both; } } I would like to know if…
1
vote
5 answers

How to select every third element with jquery?

I'm using Bootstrap 3 and styling a card list. The cards have different heights according to their content. I want to add a div.clearfix after every third card.
Card here
Amelie
  • 67
  • 2
  • 7
1
vote
2 answers

Major IE8 positioning issues

I know its a not a new concept that my site is perfect on FF,Safari and Chrome but jacked up on IE8. That being said and cutting to the chase. This is the home page that I am working on for a social network for people with CysticFibrosis.…
LightningWrist
  • 937
  • 4
  • 20
  • 37
1
vote
2 answers

Why does clearfix hack only work on floated elements?

Both floated and absolutely positioned elements are taken out of the document flow. Then why does clearfix hack only work on floating elements not upon absolutely positioned elements?
user31782
  • 7,087
  • 14
  • 68
  • 143
1
vote
1 answer

I can't figure out why my clearfix isnt working

I can't figure out why my clear fix isn't working. I have floated the nav ul with a class of main-nav to the right and the header collapsed a bit. My clearfix is right above the footer styling in the CSS. jsFiddle .clearfix::after { content=""; …
Brandon
  • 1,099
  • 1
  • 9
  • 14
1
vote
2 answers

Why is clearfix not working on this column?

I've recently taken over a few hubspot pages ffrom someone before me who built them. On this particular page, I have two columns— one on the left, and one on the right (has a gray background). The left column currently has more content than the…
Zechariah
  • 11
  • 3
1
vote
2 answers

Why does .clearfix class not work on floating element?

In this thread: What is a clearfix? I saw the best answer says the clearfix can be added directly to the last floating element: With clearfix, you only need to write HTML code:
Hanfei Sun
  • 45,281
  • 39
  • 129
  • 237
1
vote
2 answers

Clearing floating clears on an unrelated element

I think I let code speak: .aside { float: right; width: 200px; background: red; } .main { margin-right: 220px; } .main ul li { border-bottom: 1px solid black; } .main ul li img { float: left; } /*…
TiMESPLiNTER
  • 5,741
  • 2
  • 28
  • 64
1
vote
1 answer

How to properly clear these floated divs?

I thought I understood the :after method of clearfixing with CSS - but I can't seem to get it to work properly. For some reason the siblingContainer that comes after the buttonContainer containing the floated elements doesn't seem to be…
jessikwa
  • 750
  • 1
  • 8
  • 23
1
vote
1 answer

Can I use flexbox to give an element layout, and therefore deprecate clearfix?

Similar, but not the same as Is clearfix deprecated?. I have a web app targeted at modern browsers. Flexbox is used everywhere for vertical centering. The only real CSS/SASS hack is clearfix: @mixin clearfix { content: ""; display: table; …
mikemaccana
  • 110,530
  • 99
  • 389
  • 494
1
vote
3 answers

Clearfix not working in chrome 43

I've created 3 floating columns and I'm trying to use the clearfix hack, but no version of it works for me. I'm viewing my site on Chrome 43, and it looks like this: http://screencast.com/t/Dkenkh3Jq8SD but on firefox and ie it looks just fine. A…
Idanmel
  • 457
  • 4
  • 12
1
vote
0 answers

Floated Element still triggering Mouse Over, despite Clearfix

I have a table of information that I built using an unordered list containing floated . Each Float has been clearfixed, but the floated element is extending beyond the unordered list itself, stretching the tag across the page and managing to…
JPT145
  • 11
  • 4
1
vote
1 answer

SingularityGS: Why is the box-shadow missing at alpha and omega edges of of grid?

Using Singularitygs 1.3.0 together Drupal Omega 4 I have some blocks laid out in a grid, each of which has a box-shadow applied. For some reason the box-shadow effect does not display at alpha or omega edges, adjacent to the wrapping container.…
MrPaulDriver
  • 243
  • 1
  • 13