I’ve found some CSS templates where some classes have the overflow:hidden property, but no size defined. If I recall correctly, block elements stretch to fit their content unless otherwise specified. Since this is not the case, I feel that putting the overflow:hidden is pointless and I can delete it without hesitation. Is this right or am I missing something?
I’ve found some CSS templates where some classes have the overflow:hidden property, but no
Share
While that’s the main purpose of the
overflowproperty, it’s not the only effect it has on rendering. The other major effect it has is that settingoverflowto anything other thanvisible(the default) causes a block box to establish its own block formatting context.This is mainly used to contain floats without the need for a clearfix; however that isn’t the only effect of having a new BFC; there are a number of other corner cases that are better described elsewhere in the spec. Also see this lengthy write-up on the reasoning for this behavior (which, oddly enough, has very little to do with containing floats; that actually ends up being nothing more than a side effect).
So if you remove that
overflowdeclaration, you may break float layouts, among other things. I suggest avoiding doing so unless it’s absolutely necessary or you’re sure it won’t affect the layout.