Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the proper, standard way to handle CSS floats

Tags:

html

css

I have always thought that the correct way to handle CSS floats was to use either a clear div, :after pseudo class, or overflow: auto on the parent. As I understand it clear is designed to clear floats and expand the parent element back to normal. That is it's purpose, yes?

Today I found heard of an alternate method of handling the float (and parent collapse): floating the parent as well to make it expand around the floated child.

How does this align with web standards? Is there even an official float/clear standard?

like image 765
Nic Aitch Avatar asked Nov 05 '22 11:11

Nic Aitch


1 Answers

There is no particular standard here. Use whatever works in the situation.

Adding in extra HTML elements just to clear the float is frowned upon, but can occasionally be useful.

I personally like the prefer to use the Float Nearly Everything style of floating the parent, but it doesn't fit every situation.

like image 151
edeverett Avatar answered Nov 11 '22 06:11

edeverett