Floated elements should be assigned a width or unexpected behavior will occur (remember block level elements take up 100% width by default)
Elements can be either floated left or right
Elements that sit below will wrap around the floated element, it prevent this you must clear the float
blockquote {
float: right;
width: 275px;
}
float is a css property, the most common values are left and right
Float property allows you to take an element in normal flow and place it as far to the left or right of the containing element as possible
Anything else that sits inside the containing element will flow around the element that is floated
Example: Each block of text is being floated to the left {float: left}, with the width set so multiple blocks can fit on the same line
Potential issue: Paragraph #4 isn’t being displayed on a new line as expected.
Reason for this issue: Paragraph #3’s shorter height allowed another block to fit one line 1.
Fix: using the clear property
The clear property allows you to say that no element (within the same containing element) should touch the left or right- hand sides of a box
Accepts four values:
Left ({clear: left}): left-hand side of the box should not touch any other elements appearing in the same containing element.
Right ({clear: right}): right-hand side of the box should not touch any other elements appearing in the same containing element.
Both ({clear: both}): Neither the left nor right-hand sides of the box will touch elements appearing in the same containing element.
None ({clear: none}): Neither the left nor right-hand sides of the box will touch elements appearing in the same containing element.
Example: We are attempting to add a border to the <div>
that contains the three <p>
elements
Since all of the elements within the
As a result, the border is not displayed correctly
Multiple ways to fix this (here are a couple recommended approaches)
Set overflow property to auto and set width to 100%
You could just add a float property the containing <div>