by err4nt · 10y ago · 0 comments
The old trick was to set `overflow: hidden` on the element containing floated items so it would always expand to contain it - but then things like box-shadows get cut off by the containing element. To get around this, you can use an `:after` pseudo-element on the element that contains the float items. This comes after the last floated item and automatically clear the float without needing `overflow: hidden`.
Imagine markup like this:
<main>
<section></section>
<section></section>
</main>
.section {
float: left;
}
main:after {
content: '';
display: block;
clear: both;
}
The advantage of clearing a float this way over sticking `<div style=clear:both></div>` or a `.clearfix` class in your HTML is that when doing responsive design, my method keeps the clear in your CSS (and possibly only one @media query). With a `<div>` or class in your HTML you have to deal with that element at all widths - now do you have to specifically override your `.clearfix` class inside a @media query when doing responsive styles? How intuitive is that?Why? I haven't needed to use floats at all since moving to flexbox.
When isn't it? If you're developing for old (now unsupported) versions of Internet Explorer I'm not sure they'd be bothered about being turned down (unless they knew about that when applying). Just because something was done some way once doesn't make it right, and putting emphasis on 'clearing float' questions would show your company use old, bad practices.
What I would dismiss them for, however, is the cocky attitude that they never need to bother learning any "old, bad practices." I'd dismiss them for thinking they are "above" working for a company that supports technology that was released just 4 years ago. Further, I'd dismiss them for the attitude that their solution solves all the problems without considering potential drawbacks. These are all huge red flags that show they may technically be knowledgable, but are very difficult to work with. Not someone I want on my team.
"..technology that was released just 4 years ago" - if you haven't been keeping up with the news on IE10 then... yeah
"I'd dismiss them for the attitude that their solution solves all the problems without considering potential drawbacks." - no one said there weren't any drawbacks, just when compared with old bad-practice hacks.
"but are very difficult to work with. Not someone I want on my team." - it sounds like the kind of people who're using react would be sad about that.
This post is evidently about junior developers, just because something is old/established doesn't make it right or that it shouldn't be questioned, because there's usually a better way.