Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it a good practice to use float to position element?

Tags:

css

Can I use float to place the element in a webpage rather than using position: absolute or relative?

like image 420
Manish Basdeo Avatar asked Jan 20 '23 11:01

Manish Basdeo


2 Answers

Fundamentally? Sure, that's what it's there for.

Whether it's the right choice depends on what exactly you want to do.

You just need to take care of the consequences - for example, the need for using the clear property when using multiple subsequent floated elements to avoid undesired effects.

like image 67
Pekka Avatar answered Jan 22 '23 01:01

Pekka


As many other HTML and CSS features, the float property has been terribly abused. It was designed to deal with little floating elements (such as pictures in a paragraph) and it's used to create the page layout. The problem is CSS does not really provide us with better alternatives. So IMHO it isn't good practice but it's normally the way to go :)

BTW, ten years ago browsers used to have a very poor support for the position property (esp. Internet Explorer) so it was often not an option. For instance, you could not create rounded corners by placing relative boxes in the corners of the main box: they were always displaced. Luckily, this has improved a lot and nowadays is an excellent tool.

like image 32
Álvaro González Avatar answered Jan 22 '23 00:01

Álvaro González