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
1 answer

Div clearfix remove white space

My website has a header and a menubar. I'd like to position them horizontally sticked to each other like this: HEADER MENU But what happens is: HEADER WHITE SPACE MENU The code for my…
Nick
  • 169
  • 1
  • 6
  • 16
0
votes
2 answers

Clearfix not working on responsive skeleton

I use the responsive Skeleton framework (boilerplate) for my website (you can get it from here: http://www.getskeleton.com/). I have
    list column with different height. To clear nested column, the CSS says that I need to put the .clearfix class…
Ela Yudhanira
  • 66
  • 1
  • 10
0
votes
1 answer

Problems with Clearfix

I've been having trouble applying clearfix to a number of divs, I've followed several tutorials, found here and here, but still my div named Bar will not expand to hold both the logo and nav divs. Here is my markup, any and all advice would be…
0
votes
1 answer

Additional space on clearfix parent

I have a layout wherein the sidebar is fixed and the main contents container is fluid.
dork
  • 4,396
  • 2
  • 28
  • 56
0
votes
2 answers

css clearfix behavior not the same for firefox and chrome

i am using this class for css clearfix on a div which has a calculated width of 0, but has content of width x in it. .clearfix { *zoom: 1; &:before, &:after { display: table; content: ""; } &:after { clear: both; } } What is…
ghostCoder
  • 1
  • 9
  • 49
  • 72
0
votes
1 answer

Responsive design and clearfix

I have this responsive layout for a page. The
Enrique Moreno Tent
  • 24,127
  • 34
  • 104
  • 189
0
votes
2 answers

Div sidebars do not expand with content of the center column

I've got a webpage that I'm working on that when there's no content in the middle it looks fantastic. The problem came recently when I attempted to add content to the center column. I'm adding a table that contains a long list of questions that…
0
votes
3 answers

What are the downsides to using "clear:both" to clear floating divs?

It seems that the community here agrees that the old "clearfix" hack has now been depreciated and superseded by overflow:hidden. Unfortunately there are situations where even using this method causes problems. (For example: This would look like this…
Chuck Le Butt
  • 47,570
  • 62
  • 203
  • 289
0
votes
2 answers

Div Floats Left, Div Container Not Increasing Size

I'm wanting to make two divs inside a container div, one floating left, and one floating right. The left div contains the news date, title and news content, the right div includes a dropdown button and box with the media relevant to the news…
0
votes
1 answer

CSS Images not centering with radio inputs

I am just attempting inline CSS to get this right and will move it to my "styles" file when finished. What I am attempting should make all the images and radio buttons inline in the surrounding DIV. What I can't do is get them to center…
Zak
  • 6,976
  • 2
  • 26
  • 48
0
votes
2 answers

Clearfix removing margin 0 auto?

Having trouble with clearfix... when in use it will remove my centering (margin 0 auto) for the div. So, using this as an example the 'container' div would be floated to the left rather than centered within 'header'. 'Some content' would be…
user756659
  • 3,372
  • 13
  • 55
  • 110
0
votes
2 answers

Clear fix ie8 and CSS

Been making a website to try learn a bit more css and html. Thought it was going well till I tried to show it to someone in IE (I use ff) When I loaded the page up the footer seemed it to in the wrong place and i can't figure out why Here is a…
user1132612
  • 77
  • 1
  • 7
0
votes
0 answers

CSS clearfix hiding text in chrome / safari?

I have an odd problem that I'm facing. I'm using a simple CSS clearfix hack as described on CSS-Tricks to clear floats. Code snippet: *:after { content: ""; display: table; clear: both; } However, adding the above code causes the text to be…
Zach Wolf
  • 619
  • 1
  • 6
  • 15
0
votes
1 answer

Clear fix problems with overflow and pie-clearfix

I am trying to float some elements and apply clearfix so that the parent element can expand to the height and width of the children. So, I simply set up the layout as per this fiddle: http://jsfiddle.net/fMjEx/ I then wanted to float the elements…
F21
  • 32,163
  • 26
  • 99
  • 170
0
votes
2 answers

Floating and clearing five section tags

I have five section tags that I would like to float so that they are inline with each other. I have used the float / clearfix technique in the past and it has worked. I cannot figure out what i am doing wrong. CSS: #content{ padding:30px 0 0…
user1584751