Can I use float to place the element in a webpage rather than using position: absolute or relative?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With