Describe floats and how they work.

In CSS, floats are created by setting the float property of an element to a value other than none.

div {
float: left;
}

Floating an image with text wrapped around it, is a common implementation of the float property. An element can be floate…


This content originally appeared on DEV Community and was authored by Abdullah Numan

In CSS, floats are created by setting the float property of an element to a value other than none.

div {
  float: left;
}

Floating an image with text wrapped around it, is a common implementation of the float property. An element can be floated right or left, with assignable values of right, left, inline-start and inline-end.

Floating an element creates a Block Formatting Context on the element, takes the element out of the normal flow of the document, and wraps around itself line boxes that come after the element in the DOM tree.

Items floated to the left, move to the left edge of its container and those floated to the right move to the right edge.

Multiple items floated to the same edge follow the order in which they appear in the DOM tree, with the first one moved to the edge, then the next one beside it, and so on -- ending up with the last one farthest from the edge. If there is no space to accommodate all floated items, they move to the next line.

In almost all cases, using a float also involves clearing it from the items that come after itself, because line boxes (e.g. text nodes) wrap around floated items. Clearing a float from an element results in moving the element below the float.

Floats, along with several clearing techniques, were used to create multi-column layouts, but flex and grid items are used for this purpose.

References

  1. Floats
  2. float
  3. clear


This content originally appeared on DEV Community and was authored by Abdullah Numan


Print Share Comment Cite Upload Translate Updates
APA

Abdullah Numan | Sciencx (2022-06-23T12:33:27+00:00) Describe floats and how they work.. Retrieved from https://www.scien.cx/2022/06/23/describe-floats-and-how-they-work/

MLA
" » Describe floats and how they work.." Abdullah Numan | Sciencx - Thursday June 23, 2022, https://www.scien.cx/2022/06/23/describe-floats-and-how-they-work/
HARVARD
Abdullah Numan | Sciencx Thursday June 23, 2022 » Describe floats and how they work.., viewed ,<https://www.scien.cx/2022/06/23/describe-floats-and-how-they-work/>
VANCOUVER
Abdullah Numan | Sciencx - » Describe floats and how they work.. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/06/23/describe-floats-and-how-they-work/
CHICAGO
" » Describe floats and how they work.." Abdullah Numan | Sciencx - Accessed . https://www.scien.cx/2022/06/23/describe-floats-and-how-they-work/
IEEE
" » Describe floats and how they work.." Abdullah Numan | Sciencx [Online]. Available: https://www.scien.cx/2022/06/23/describe-floats-and-how-they-work/. [Accessed: ]
rf:citation
» Describe floats and how they work. | Abdullah Numan | Sciencx | https://www.scien.cx/2022/06/23/describe-floats-and-how-they-work/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.