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

jQuery append doesn't see changes?

I have some scripting that modifies my web application. What it basically does is: Add dynamic elements to the DOM Resize some DOM elements to fit the window height and other stuff... So, I do: $(document).ready -> …
frarees
  • 2,190
  • 3
  • 17
  • 22
0
votes
1 answer

How to correctly apply the .clearfix:after class to HTML?

I'm currently trying (and failing) to get the .clearfix:after clearing fix that is detailed on stack here, and on position is everything here to work in Chrome and Firefox. My understanding is that the .clearfix class should be added to the element…
john k
  • 1,086
  • 4
  • 14
  • 19
0
votes
1 answer

Why is my media query putting elements out of their container?

Hello Community: I am learning GridSystems right now. I made 2 media queries depending on the screen size: the first one is for 768px the second one is for 480px. but when i adapt the screen size, the elements are coming out of their container. Why?…
No Body
  • 3
  • 4
0
votes
1 answer

Responsive Media Card Image on left, text on right

Here's the my current code in jsfiddle:
dev1791456
  • 23
  • 1
  • 2
0
votes
0 answers

Why does an empty block exists whereas an empty inline does not?

I was learning about floats and clearfix. So if all the elements of a container are floats then the container shrinks, and to have height, container must have a non-float element. So when an empty inline is inserted into the container, nothing…
Yogesh Bhatt
  • 127
  • 2
  • 9
0
votes
4 answers

Element widths not aligning themselves properly

I'm really struggling here trying to figure out what is going on. I have an HTML with a header, a sidebar, and a central content page. The sidebar and central content are in the same div, which also acts as their clearfix. I floated the sidebar to…
Dasphillipbrau
  • 524
  • 2
  • 8
  • 17
0
votes
3 answers

How to use "clearfix" css in nested blocks?

I'd found, that css "clearfix" example not work properly when there are nested float:left blocks. Here is an example: .left { float: left; width: 100px; height: 200px; background: green; } .right { margin-left: 100px; …
eurobax
  • 3
  • 2
0
votes
1 answer

How to Add Margin to Relative Div Overflowing Parent to Move Content Down

I have created a div that overlaps its parent, and the margins after the div are not behaving as expected. I expect the content following the div to appear after the overlowing div, but it's not. Expected Behavior : expected_image Reality…
0
votes
1 answer

CSS Clear Float not working with Media Queries

I'm trying to clear two elements from floating, but it's not working and I can't figure out why. The answer is probably (literally) right before my eyes. It may have to do with my Media Queries or other styles before the clear. The clear itself…
Cinder
  • 319
  • 2
  • 15
0
votes
1 answer

bootstrap clearfix not working. Holes in layout chrome

Hey guys I created my own custom cards in bootstrap 3 as I need to support rather old browsers and cant yet upgrade to bootstrap four. The cards have a video in them. a title and a button. Heres the css for the cards. .card{width: 100%;…
codernoob6
  • 61
  • 1
  • 6
0
votes
1 answer

Is clearfix a good technique for float clearing in css

I was using clearfix to clear the floating effect in CSS, but I was told that it's not really good technique and I should use something else. Is that true? And if it is, are there other alternatives that would still make my CSS validated? Many…
Shaoz
  • 10,573
  • 26
  • 72
  • 100
0
votes
1 answer

Floats not working, Second Background Image not registering as a background, Centering things?

So to start off let me just note that I am not tech savy at all. I find most computers difficult and I wouldn't be taking this class unless I needed it to graduate from my university. I'm trying to make a webpage for class thats due tomorrow and I…
0
votes
0 answers

Attribute selector in clearfix implementation?

I came across the clearfix implementation below. What could be the reason for the choice of the attribute selector (div[class="foobar"])? I cannot figure out any good reason for it. Why didn't the author use div.foobar? div.foobar:after { …
pogopaule
  • 1,533
  • 2
  • 10
  • 17
0
votes
3 answers

How can i override previous styling in a wordpress theme?

Ok, this is the styling I want to be used .suggestion-taxonomies-product-visibility span { display: inline-block; float: left; padding-left: 10px; } The usual of mentioning the element here doesn't seem to work, any ideas?…
MittenMits
  • 59
  • 10
0
votes
1 answer

Div don't stack without additional clearfix in bootstrap

I am relatively new to bootstrap and created a first main page with a big jumbotron and 3 horizontally aligned columns below. All include one image and text below. See code here:
Chris
  • 13
  • 3