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
2
votes
2 answers

Are there any disadvantages to adding clearfix to all divs?

On a layout I'm working on (and in most cases otherwise), I can't think of any instances where I wouldn't want a div to not contain its floated children. So I'm thinking instead of adding a clearfix class to every element that needs it (mostly…
ccnokes
  • 6,885
  • 5
  • 47
  • 54
2
votes
1 answer

Collapsing DIV in IE8

If you view the following website in IE9 (or any other modern browser) you will see the effect I am going for. However viewed in IE8 or lower the header DIV that contains the mans photo collapses to what appears to be 0 height. I have tried…
Pete Norris
  • 1,056
  • 7
  • 24
  • 36
2
votes
1 answer

Unordered List Clearfix

I have an unordered list and each list element contains a photo and a headline. My CSS sets up the grid to be a grid, where each row contains three photos. Sometimes the headline (or photo caption) is longer than the width of the photo and has to…
musubi
  • 1,256
  • 3
  • 14
  • 22
2
votes
1 answer

Clear child floats without clearing 'external' floats

The most popular way of clearing a group of floats is to use clear:both; on the parent's :after pseudo-element. For example this: .group:after { visibility: hidden; display: block; content: ""; clear: both; height: 0; } *…
Cameron Martin
  • 5,952
  • 2
  • 40
  • 53
2
votes
1 answer

Issues with clearfix

I have created a html and can be found http://temp87.web44.net/temp.html. Problem what i'm facing is there is a gray strip at the bottom of page after footer and the page is not occupying 100% of browser. CSS which is causing the…
user1184100
  • 6,742
  • 29
  • 80
  • 121
1
vote
5 answers

Button sticking out of form

I have a form that looks like this: Removing the mb-3 class does nothing to help, it just removes the spaces between the inputs. How am I supposed to ensure the button stays within the blue box?
Ryolu
  • 523
  • 3
  • 16
1
vote
1 answer

How do I remove clearfix from woocommerce shortcutcode

I am using wordpress and I just pasted woocommerce products shortcut code. So, I want to know how do I remove clearfix div from woocommerce shortcutcode or HTML, any ideas? As you can see the screenshot (Sorry have keep it hidden for some…
jeet singh
  • 71
  • 10
1
vote
0 answers

after applying clearfix hack to figure tag, the figcaption gets excluded and goes out of the figure

@media(min-width: 1071) { .align-left { float: left; width: 100%; margin: auto; max-height: 350 ; max-width: 450 ; } .align-center { float: inherit; …
1
vote
1 answer

ACF Repeater Fields & Clearfix / Styling when displaying

First time posting, been using these forums as a resource for a while though... Hoping you can help. I’m scratching my head on a PHP thing & wondered if you might have any ideas Here’s the situation, ‘backstory’ first; I'm typically working in…
1
vote
1 answer

Whats wrong if I use floating element to all html tags?

I'm currently using 'float:left' to all of my tags when slicing. Whats wrong with it? I think, the pros is I need not to do "clearing hacks" at all. Sorry for my poor english.
1
vote
3 answers

CSS expand div right floated div

I have a main div (purple) for this html header which splits in 2 other divs contaning the logo (red) and some other information on the right (green) I have a clear fix for purple which makes both red and green float nicelly, both are floated to the…
zanona
  • 12,345
  • 25
  • 86
  • 141
1
vote
0 answers

Clearfix on blogger widget

I recently added a new widget on my blog, but it seems that a line document.write('
  • ');if(showpostthumbnails==true) causes some extra empty space under the link. Deleting the whole line removes link separators and the whole…
  • 1
    vote
    2 answers

    CSS: Parent/Child height issue

    I'm struggling with a sidebar height. My container is now showing the correct height (that of the content inside), but my sidebar that should be using 100% of that height is still not appearing. I've implemented one of the suggestions below…
    Tom Perkins
    • 499
    • 3
    • 7
    • 16
    1
    vote
    2 answers

    Overlapping sections, the content of section goes beyond this section

    I have problem: first section - header is attachment fixed, and when I reduce the browser window, the background only covers a small portion of the section, the rest of the content is under another section, or completely out of the background. As…
    Tubaris
    • 11
    • 5
    1
    vote
    1 answer

    Where to apply clearfix(es)?

    Top margin of first card is result of float: right applied on button. If I remove that right float, top margin appears above second card. What's proper way to fix this? Where to apply clearfix(es)? check example on codepen
    ridjis
    • 55
    • 10