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
4 answers

CSS vh and vw: Why does my div overlap with the div above it?

In the following SSCCE, why does the #sliderArea div overlap the #topBar div above it, while div is a block-level element? I expected it to appear below the #topBar? JsFiddle here. #left-div { float: left; } #right-div { float:…
Solace
  • 8,612
  • 22
  • 95
  • 183
1
vote
1 answer

How can use Bootstrap clearfix for clearing floats?

I have a WordPress theme in my single.php page. Below follows the HTML code:
single post…
Shwan Namiq
  • 631
  • 8
  • 21
1
vote
1 answer

Tabbing between links causes issues with pseudo-elements in Chrome

In Chrome, click in the results pane and hit tab to focus on the first link here: http://jsfiddle.net/2q6c7c36/2/ notice how the contents of .box "jump up" outside of its border? It appears to be caused by the clearfix class I'm using. Is this a bug…
launchoverit
  • 4,807
  • 4
  • 20
  • 23
1
vote
1 answer

'clearfix' OR 'overflow: hidden' Which is better for multiple listing?

As we know there are multiple ways to clear a div. I always preferred the clearfix (bootstap) method. But when there need to clear a list elements/divs (multiple) like following code
  • some floated elements goes here..…
amol
  • 1,535
  • 9
  • 10
1
vote
2 answers

Clearfix not working with float: left and float: right in

I am designing the comments section of a blog right now. My markup is a ordered list item per comment. Inside I have a heading floated left and some span-tag floated right in a header. I tried to clearfix the header (e. g. every clearfix-hack from…
Florian_1990
  • 121
  • 6
1
vote
0 answers

IE7 container of floated elements not expanding, clear and zoom not working

Edited; see bottom of post I have a layout that works perfectly in everything except Internet Explorer 7. I have a container div that has a width and hasLayout (I've tried zoom and various other things that ought to set this, but nothing changes).…
qwigoqwaga
  • 37
  • 8
1
vote
2 answers

CSS - full width element within narrow parent?

I have a blog post that is 960 pixels wide. I want parts of this blogpost to cover 100% of the viewport (from left: 0 to right: 0). It's fairly easy to do with absolute positioning but using this approach it's impossible to clear these 100%-wide…
Wordpressor
  • 7,173
  • 23
  • 69
  • 108
1
vote
1 answer

Remove gray line in clearfix from

I would like to remove the gray line caused by the clearfix elements in my D7 theme (MD Photo). In particular, the div class="wrap clearfix" element, which has an unnecessary gray line at the bottom of the body elements. I have tried quite a few…
Ross
  • 305
  • 1
  • 2
  • 10
1
vote
1 answer

Clearfix class for HTML5Boilerplate is not being placed on a containing element

The website stinsonandassociates.com uses a clearfix on its mobile nav menu (seen at small screen widths). It is not working, but I am curious as to why the clearfix class I am applying (using HTML5Boilerplate) is not at least recognizing the…
user1498724
  • 147
  • 1
  • 1
  • 5
1
vote
3 answers

Why does it work without clearfix?

I thought I understood what the clearfix is for. But it works as desired without clearfix. Why is that? This is my HTML:

Title

Headline 1 with a very long title

Lorem ipsum dolor sit…

Xiphias
  • 4,468
  • 4
  • 28
  • 51
1
vote
2 answers

Where to apply the clearfix class

So I'm having a problem with the last paragraph apparently not clearing and slipping into the middle of the h1 and nav. But when I put a div with a clear:both property before the paragraph it appears to work. Bear with my fiddle, please. I used a…
kentz
  • 47
  • 6
1
vote
2 answers

micro clearfix doesn't work

i am using nicolas gallagher's micro-clearfix in my Fixed layout. And in my layout the green colored footer does not appear. Which means the clearfix doesn't work properly
It worked yesterday.
  • 4,507
  • 11
  • 46
  • 81
1
vote
0 answers

Contenteditable bug in chrome

I'm using Chrome 27.0.1453.93 and Ubuntu 13.04 If we have contenteditable="true" on element with float set to left or right, and if the parent of this element has clearfix class, we can see strange behaviour, when content becomes editable after…
eawer
  • 1,398
  • 3
  • 13
  • 25
1
vote
1 answer

100% height div in background cover div

Currently I have a web page with a background image size of cover. I would like 2 divs inside of this div with 100% height. These divs need to be responsive. I need the leftside div to have an image to sit on the bottom. I am using clearfix on the…
jfarr
  • 41
  • 4
  • 11
1
vote
2 answers

Need to modify a Wordpress Homepage template to include ignored contents of editor field

I am attempting to tweak an existing Wordpress theme called Pytheas (for a quickie video tour of its features, visit this page). It is a WP theme oriented toward displaying portfolios. The homepage features a slideshow. My aim is to replace the…
DocBadwrench
  • 149
  • 1
  • 7