{"id":239,"date":"2020-08-14T19:46:35","date_gmt":"2020-08-14T19:46:35","guid":{"rendered":"https:\/\/datatype.co.in\/blog\/?p=239"},"modified":"2020-08-20T09:35:37","modified_gmt":"2020-08-20T09:35:37","slug":"use-of-css-float-and-clear-properties","status":"publish","type":"post","link":"https:\/\/datatype.co.in\/blog\/use-of-css-float-and-clear-properties\/","title":{"rendered":"Use of CSS float and clear Properties"},"content":{"rendered":"\n<p>Are you struggling to place two or more divisions side by side in a web page? Then you should checkout CSS <code>float<\/code> property.<\/p>\n\n\n\n<p>In this article I will show you how to use CSS float property to display two divisions side by side. Basically we will float one div to left and the other one to right. The width of each div should be around 50%. At the end of floating divs, it is important to use an empty div with class clear-fix. If we forget to add this div, then our rest of the page element will overflow and it will ruin page design. Therefore, whenever you use CSS <code>float <\/code>property, don&#8217;t miss to use <code>clear <\/code>property to fix the floating elements.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;div id=\"container\">\n  \n  &lt;div class=\"left\"> \n    This is left division\n  &lt;\/div>\n\n  &lt;div class=\"right\"> \n    This is right division\n  &lt;\/div>\n  &lt;!-- This div is important -->\n  &lt;div class=\"clear-fix\">&lt;\/div>\n\n&lt;div> <\/code><\/pre>\n\n\n\n<p>Add the following CSS code in your css file :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.left{\n   width: 49%;\n   float: left;\n   border: 1px solid #ccc\n}\n.right{\n   width: 49%;\n   float: right;\n   border: 1px solid #ccc\n}\n.clear-fix{\n   clear: both\n}<\/code><\/pre>\n\n\n\n<p>Notice the use of last div with class clear-fix. <\/p>\n\n\n\n<p>The <code>float <\/code>property accepts 4 values &#8211; <em><code>left<\/code><\/em>, <em><code>right<\/code><\/em>, <em><code>inherit <\/code><\/em>and <em><code>none<\/code><\/em>.<\/p>\n\n\n\n<p>Here is complete example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;html>\n&lt;head>\n   &lt;title>Use Of CSS Float &amp; Clear Properties&lt;\/title>\n   &lt;style>\n      .left{\n  \t width: 49%;\n\t float: left;\n         border: 1px solid #ccc\n       }\n     .right{\n  \t width: 49%;\n\t float: right;\n         border: 1px solid #ccc\n       }\n       .clear-fix{\n  \t  clear: both\n       }\n   &lt;\/style>\n&lt;\/head>\n&lt;body>\n&lt;div id=\"container\">\n  &lt;div class=\"left\"> \n    This is left division\n  &lt;\/div>\n  &lt;div class=\"right\"> \n    This is right division\n  &lt;\/div>\n  &lt;!-- This div is important -->\n  &lt;div class=\"clear-fix\">&lt;\/div>\n&lt;div> \n&lt;\/body>\n&lt;\/html><\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"375\" src=\"https:\/\/datatype.co.in\/blog\/wp-content\/uploads\/2020\/08\/image-1024x375.png\" alt=\"\" class=\"wp-image-243\" srcset=\"https:\/\/datatype.co.in\/blog\/wp-content\/uploads\/2020\/08\/image-1024x375.png 1024w, https:\/\/datatype.co.in\/blog\/wp-content\/uploads\/2020\/08\/image-300x110.png 300w, https:\/\/datatype.co.in\/blog\/wp-content\/uploads\/2020\/08\/image-768x281.png 768w, https:\/\/datatype.co.in\/blog\/wp-content\/uploads\/2020\/08\/image-710x260.png 710w, https:\/\/datatype.co.in\/blog\/wp-content\/uploads\/2020\/08\/image.png 1116w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>If you want to display three divisions side by side, use two divs with class <code>.left<\/code> and one div with class <code>.right<\/code><em> <\/em>(or, two divs with class <code>.right<\/code><em> <\/em>and one div with class <code>.left<\/code>). At the end you will have to add one empty div with class <code>.clear-fix<\/code><em> <\/em>in both cases. Each div <code>width <\/code>should be around 33.3% to fit all in a line.<\/p>\n\n\n\n<p>You can try this code here :  <a href=\"https:\/\/datatype.co.in\/code-editor\">Datatype Code Editor<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Are you struggling to place two or more divisions side by side in a web page? Then you should checkout CSS float property. In this article I will show you&nbsp;[ &hellip; ]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[126,128,125,127,124,123],"class_list":["post-239","post","type-post","status-publish","format-standard","hentry","category-css","tag-css-clear","tag-css-display-divs-side-by-side","tag-css-float","tag-css-float-example","tag-use-of-css-clear-property","tag-use-of-css-float-property","list-style-post"],"_links":{"self":[{"href":"https:\/\/datatype.co.in\/blog\/wp-json\/wp\/v2\/posts\/239","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/datatype.co.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/datatype.co.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/datatype.co.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/datatype.co.in\/blog\/wp-json\/wp\/v2\/comments?post=239"}],"version-history":[{"count":12,"href":"https:\/\/datatype.co.in\/blog\/wp-json\/wp\/v2\/posts\/239\/revisions"}],"predecessor-version":[{"id":363,"href":"https:\/\/datatype.co.in\/blog\/wp-json\/wp\/v2\/posts\/239\/revisions\/363"}],"wp:attachment":[{"href":"https:\/\/datatype.co.in\/blog\/wp-json\/wp\/v2\/media?parent=239"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/datatype.co.in\/blog\/wp-json\/wp\/v2\/categories?post=239"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/datatype.co.in\/blog\/wp-json\/wp\/v2\/tags?post=239"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}