0

Why in this code the div1 comes under div2 border?why they both don't have seprate border like side by side?

https://code.sololearn.com/Wvz8C88pJhCm/?ref=app

31st May 2020, 6:29 AM
THE CRAZY ONE ✌️
THE CRAZY ONE ✌️ - avatar
3 odpowiedzi
+ 2
Give him property margin-top:100px
31st May 2020, 6:48 AM
Muhammad Galhoum
Muhammad Galhoum - avatar
+ 2
The code after modification: <!DOCTYPE html> <html> <head> <style> .div1 { float: left; width: 100px; height: 50px; margin: 10px; border: 3px solid #73AD21; } .div2 { border: 1px solid red; margin-top:100px } .div3 { float: left; width: 100px; height: 50px; margin: 10px; border: 3px solid #73AD21; } .div4 { border: 1px solid red; clear: left; } </style> </head> <body> <h2>Without clear</h2> <div class="div1">div1</div> <div class="div2">div2 - Notice that div2 is after div1 in the HTML code. However, since div1 floats to the left, the text in div2 flows around div1.</div> <br><br> <h2>With clear</h2> <div class="div3">div3</div> <div class="div4">div4 - Here, clear: left; moves div4 down below the floating div3. The value "left" clears elements floated to the left. You can also clear "right" and "both".</div> </body> </html>
31st May 2020, 6:51 AM
Muhammad Galhoum
Muhammad Galhoum - avatar
+ 1
Becoz u float div1 left Try to remove it u get what u want i.e., separated para
31st May 2020, 6:50 AM
Abhay
Abhay - avatar