CSS Float & Clear
Published: 2022-12-24 15:11:47

<h1 id="heading-float"><strong>FLOAT</strong></h1>
<ul>
<li>The CSS float property specifies how an element should float.</li>
<li>so let’s Understand with the example</li>
<li>left - The element floats to the left of its container</li>
<li>right - The element floats to the right of its container</li>
<li>none - The element does not float (will be displayed just where it occurs in the text). This is default</li>
<li>inherit - The element inherits the float value of its parent</li>
<li>so here in example we have very 2 images there will taking space and not beutifull visually too</li>
<li>so make it them right or left side we used</li>
<li><strong>float:left</strong> or <strong>float:right</strong></li>
</ul>
<h2 id="heading-example1st-of-float">Example:1st of float</h2>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1670240879013/E3ahmaZTE.png" alt="1.png" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1670240886430/lHMG5vaQW.jpeg" alt="2.jpeg" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1670240891383/K_kWZ4KCi.png" alt="3.png" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1670240896170/tQO4HgbQt.png" alt="4.png" /></p>
<h2 id="heading-example2nd-of-float">Example:2nd of float</h2>
<ul>
<li>when we make navigation bar and we applied float and  our element(li)  out from ul container.</li>
<li>when we float  ul make it smaller so li comes out of ul  to prevent this overflow . property of overflow comes in picture</li>
<li>this li overflow from ul stop by <strong>overflow : auto</strong></li>
</ul>
<p>code</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1670241000616/zNYxvsP4v.png" alt="5.png" /></p>
<p>output</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1670241027591/FUPcHqXK_.png" alt="51.png" /></p>
<p>code</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1670241044863/Y6y9OIrKe.png" alt="6.png" /></p>
<p>output</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1670241056478/WB2-LiLTy.png" alt="7.png" /></p>
<h1 id="heading-clear-property"><strong>CLEAR PROPERTY</strong></h1>
<ul>
<li>CLEAR PROPERTY APPLY ON FLOATED ELEMENT AND NON-FLOATED ELEMENT TOO</li>
<li>clear property decide the other floated element stay left or right of floated element</li>
<li>The clear property specifies what elements can float beside the cleared element and on which side.</li>
<li>The clear property can have one of the following values:</li>
<li>none - Allows floating elements on both sides. This is default</li>
<li>left - No floating elements allowed on the left side</li>
<li>right- No floating elements allowed on the right side</li>
<li>both - No floating elements allowed on either the left or the right side</li>
<li>inherit - The element inherits the clear value of its parent</li>
<li>The most common way to use the clear property is after you have used a float property on an element.</li>
</ul>
<p>When clearing floats, you should match the clear to the float: If an element is floated to the left, then you should clear to the left. Your floated element will continue to float, but the cleared element will appear below it on the web page.</p>
<hr />
<p>there is only one difference with you can make change in output1 and output 2 which i<strong>s clear:right;</strong> </p>
<p><strong>output 1</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1670241142375/FScGZiBe0.png" alt="8.png" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1670241151037/63Mq-6mVR.png" alt="9.png" /></p>
<p><strong>output 2</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1670241172611/5Osoe4r6y.png" alt="10.png" /></p>
</br><p style="color:#757CF9;">This article is published w/ <a target="_blank" href="https://scattr.io?ref=dev">Scattr  ↗️</a></p>