float
Quick Summary for float
The float CSS property places an element on the left or right side of its container, allowing text and inline elements to wrap around it. The element is removed from the normal flow of the page, though still remaining a part of the flow (in contrast to absolute positioning).
Code Usage for float
/* Keyword values */ float: left; float: right; float: none; float: inline-start; float: inline-end;  /* Global values */ float: inherit; float: initial; float: revert; float: unset; 
More Details for float

float

The float CSS property places an element on the left or right side of its container, allowing text and inline elements to wrap around it. The element is removed from the normal flow of the page, though still remaining a part of the flow (in contrast to absolute positioning).

A floating element is one where the computed value of float is not none.

As float implies the use of the block layout, it modifies the computed value of the display values, in some cases:

Specified value Computed value
inline block
inline-block block
inline-table table
table-row block
table-row-group block
table-column block
table-column-group block
table-cell block
table-caption block
table-header-group block
table-footer-group block
inline-flex flex
inline-grid grid
other unchanged

Note: If you're referring to this property from JavaScript as a member of the HTMLElement.style object, modern browsers support float, but in older browsers you have to spell it as cssFloat, with Internet Explorer versions 8 and older using styleFloat. This was an exception to the rule, that the name of the DOM member is the camel-case name of the dash-separated CSS name (because "float" is a reserved word in JavaScript, as seen in the need to escape "class" as "className" and escape <label>'s "for" as "htmlFor").

Syntax

/* Keyword values */ float: left; float: right; float: none; float: inline-start; float: inline-end;  /* Global values */ float: inherit; float: initial; float: revert; float: unset; 

The float property is specified as a single keyword, chosen from the list of values below.

Values

left

The element must float on the left side of its containing block.

right

The element must float on the right side of its containing block.

none

The element must not float.

inline-start

The element must float on the start side of its containing block. That is the left side with ltr scripts, and the right side with rtl scripts.

inline-end

The element must float on the end side of its containing block. That is the right side with ltr scripts, and the left side with rtl scripts.

Formal definition

Initial valuenone
Applies toall elements, but has no effect if the value of display is none.
Inheritedno
Computed valueas specified
Animation typediscrete

Formal syntax

left | right | none | inline-start | inline-end

Examples

How floated elements are positioned

As mentioned above, when an element is floated, it is taken out of the normal flow of the document (though still remaining part of it). It is shifted to the left, or right, until it touches the edge of its containing box, or another floated element.

In this example, there are three colored squares. Two are floated left, and one is floated right. Note that the second "left" square is placed to the right of the first. Additional squares would continue to stack to the right, until they filled the containing box, after which they would wrap to the next line.

A floated element is at least as tall as its tallest nested floated children. We gave the parent width: 100% and floated it to ensure it is tall enough to encompass its floated children, and to make sure it takes up the width of the parent so we don't have to clear its adjacent sibling.

HTML
<section>   <div class="left">1</div>   <div class="left">2</div>   <div class="right">3</div>   <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.      Morbi tristique sapien ac erat tincidunt, sit amet dignissim      lectus vulputate. Donec id iaculis velit. Aliquam vel      malesuada erat. Praesent non magna ac massa aliquet tincidunt      vel in massa. Phasellus feugiat est vel leo finibus congue.</p> </section> 
CSS
section {   box-sizing: border-box;   border: 1px solid blue;   width: 100%;   float: left; }  div {   margin: 5px;   width: 50px;   height: 150px; }  .left {   float: left;   background: pink; }  .right {   float: right;   background: cyan; } 
Result

Clearing floats

Sometimes you may want to force an item to move below any floated elements. For instance, you may want paragraphs to remain adjacent to floats, but force headings to be on their own line. See clear for examples.

Specifications

Specification
CSS Logical Properties and Values Level 1 # float-clear

See also

Block formatting context Use clear to force an item to move below a floated element. Select your preferred language English (US)DeutschEspañolFrançais日本語한국어PolskiPortuguês (do Brasil)Русский中文 (简体) Change language

No Items Found.

Add Comment
Type in a Nick Name here
 
Other Categories in CSS
css
Search CSS
Search CSS by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code here, mostly for my reference. Also if i find a good link, i usually add it here and then forget about it. more...

Subscribe to weekly updates about things i have added to the site or thought interesting during the last week.

You could also follow me on twitter or not... does anyone even use twitter anymore?

If you found something useful or like my work, you can buy me a coffee here. Mmm Coffee. ☕

❤️👩‍💻🎮

🪦 2000 - 16 Oct 2022 - Boots
Random Quote

"Olivia, my eldest daughter, caught measles when she was seven years old. As the illness took its usual course I can remember reading to her often in bed and not feeling particularly alarmed about it. Then one morning, when she was well on the road to recovery, I was sitting on her bed showing her how to fashion little animals out of coloured pipe-cleaners, and when it came to her turn to make one herself, I noticed that her fingers and her mind were not working together and she couldn’t do anything. 'Are you feeling all right?' I asked her. 'I feel all sleepy,' she said. In an hour, she was unconscious. In twelve hours she was dead. The measles had turned into a terrible thing called measles encephalitis and there was nothing the doctors could do to save her. That was...in 1962, but even now, if a child with measles happens to develop the same deadly reaction from measles as Olivia did, there would still be nothing the doctors could do to help her. On the other hand, there is today something that parents can do to make sure that this sort of tragedy does not happen to a child of theirs. They can insist that their child is immunised against measles. ...I dedicated two of my books to Olivia, the first was ‘James and the Giant Peach’. That was when she was still alive. The second was ‘The BFG’, dedicated to her memory after she had died from measles. You will see her name at the beginning of each of these books. And I know how happy she would be if only she could know that her death had helped to save a good deal of illness and death among other children."

I just checked google books for BFG, and the dedication is there. 

https://www.google.com.au/books/edition/_/quybcXrFhCIC?hl=en&gbpv=1 


Roald Dahl, 1986
Random CSS Property

:focus-within

The :focus-within CSS pseudo-class matches an element if the element or any of its descendants are focused. In other words, it represents an element that is itself matched by the :focus pseudo-class or has a descendant that is matched by :focus. (This includes descendants in shadow trees.)
:focus-within css reference