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

Clearfix doesn't work when I want multiple images superposing

I want 3 images on top of each other (so i can switch between them with the slider). I use the relative/absolute technique. Strangely, the result is floating outside the div (see the picture below). When I try to fix it with clearfix, it just cancel…
fransua
  • 29
  • 1
  • 1
  • 10
0
votes
2 answers

CSS Float content creating whitespace and overlapping other div

I'm in the midst of creating a responsive portfolio at the moment and I'm running into a bit of trouble. Before a certain breakpoint (css media query), the second and third paragraph in the 'About' section of my website are in floats. As the window…
WebDevKid
  • 51
  • 1
  • 6
0
votes
1 answer

CSS clearfix doesn't seem to work

I'm trying to use clearfix instead of clear both, but it doesn't work for some reason. I did everything as the tutorials. What should I do to make it work? * { margin: 0; padding: 0; } /* .first_div { …
Ahmadz Issa
  • 669
  • 3
  • 12
  • 36
0
votes
1 answer

Add condition ngFor outside loop

I want to add a div with class clearfix but I need to add it outside the loop. Is any way to achieve that?
cor
  • 3,323
  • 25
  • 46
0
votes
2 answers

Make a div adjust its height to its absolutely positioned children

I have a div element (default positioning) containing and h1 and a link, both of which have absolute positioning. Naturally, the div elements height collapses. How do I make the div element adjust its height to its two children? I have tried…
Lukeception
  • 75
  • 1
  • 6
0
votes
0 answers

Firefox Float: Post Feed Overlapping Header Image

I'm having this strange issue on a website I'm working on using a modified Wordpress Twenty Sixteen theme: http://olderbeast.com/ It looks fine on Chrome and Opera, but on Firefox and Edge the blog feed ignores the new header image and overlaps it…
0
votes
1 answer

Is it possible to overwrite a clearfix with a
?

Currently, I have a clearfix wrapped around a large body of content. I have multiple sets of images on the left and text on the right with a
under each. The only issue is that sometimes I don't have enough text to balance the image out, and…
jonbon
  • 1,142
  • 3
  • 12
  • 37
0
votes
1 answer

100% height div disappears

I am attempting a liquid web design that includes a shadow on the outside of the content box. This cal all be seen here: http://mikesidelka.com/2/ So I attempted to do this, by having the content into one containing div, and the shadows in a…
0
votes
1 answer

Clearfix not working on div with video in it

I have tried a lot of different types of clearfixes but none are working. I am trying to make a full-width video header that has text infront of it, but you can scroll down past it as well. This is what I have: HTML:
georgej
  • 3,041
  • 6
  • 24
  • 46
0
votes
1 answer

Clearfix not working with a fixed width column

I am new to Bootstrap and I am having a problem with clearfix. I am trying to design a website with 3 content columns (of variable height) and a 4th column with a fixed width for advertising.