1. Problem
2. Solution 1. clear: both Add an element with the attribute clear:both; after the last floated element. <style> div.parent>div.fl{ float: left; width: 200px; height: 200px; margin-right: 20px; border: 1px solid red; } .clear{ clear: both; } </style> <div class="parent"> <div class="fl">1</div> <div class="fl">2</div> <div class="fl">3</div> <div class="fl">4</div> <div class="clear">5</div> </div> Add the :after pseudo-element with the clear:both; attribute to the parent element. <style> div.parent>div.fl{ float: left; width: 200px; height: 200px; margin-right: 20px; border: 1px solid red; } .clear:after{ content: ''; display: block; clear: both; } </style> <div class="parent clear"> <div class="fl">1</div> <div class="fl">2</div> <div class="fl">3</div> <div class="fl">4</div> </div> Note: Pseudo-elements are inline by default, so when using pseudo-elements, you must set the attribute display: block;. 2. overflow:auto / overflow:hidden <style> div.parent{ overflow:auto; /*overflow: hidden; also works*/ } div.parent>div.fl{ float: left; width: 200px; height: 200px; margin-right: 20px; border: 1px solid red; } </style> <div class="parent"> <div class="fl">1</div> <div class="fl">2</div> <div class="fl">3</div> <div class="fl">4</div> </div> 3. Floating parent elements <style> div.parent{ float: left; } div.parent>div.fl{ float: left; width: 200px; height: 200px; margin-right: 20px; border: 1px solid red; } </style> <div class="parent"> <div class="fl">1</div> <div class="fl">2</div> <div class="fl">3</div> <div class="fl">4</div> </div> Note: This method is generally not used, as it will cause layout problems for the parent element. This concludes this article on the problems and solutions caused by floating elements. For more information about problems caused by floating elements, please search 123WORDPRESS.COM’s previous articles or continue to browse the related articles below. We hope that everyone will support 123WORDPRESS.COM in the future! |
<<: Three BOM objects in JavaScript
>>: VMware Workstation virtual machine installation operation method
Solution 1 Completely uninstall and delete all da...
The blogger hasn't used MySQL for a month or ...
Find the running container id docker ps Find the ...
Problem to be solved Mainly for cross-level commu...
Preface We all know that the QR codes in official...
Table of contents 1. What is copy_{to,from}_user(...
Table of contents 1. Mutex 1. Initialization of m...
Table of contents Structural inheritance (impleme...
Table of contents Preface Relationships between v...
1. Create table statement: CREATE TABLE `employee...
First, the HTML code to embed the video in the pag...
I believe everyone knows HTML and CSS, knows the ...
<br />This tag is used to create a multi-lin...
1. Disk partition: 2. fdisk partition If the disk...
Table of contents 1. Signal List 1.1. Real-time s...