Float and clear
Floating means taking the elements out of the regular document stream. What should I do? First, the effect of text on images in traditional publications can be achieved, and second, the block-level elements originally listed (stacked) from top to bottom can be changed to parallel between left and right to achievePartitionLayout.
Floating and clearing are the swords used to organize the page layout.FloatAndClearAttribute.
After the floating element is detached from the regular document stream, the elements that followed it will be raised up to the same level as the floating element when the space permits.
View results
How to enclose floating Elements
The floating element is out of the mainstream (document Liu), and its parent element (organization) cannot see it, so it escaped from the encirclement. this is not what the Organization wants, so we will introduce how to enclose floating sub-elements.
<section> <p>It's fun to float.</p></section><footer>Here is the footer.</footer>
Add overflow: hidden to the parent Element
Add overflow: hidden to the parent element of the floating element, and force the parent element to enclose the floating element.
<style> section { border: 1px solid blue; margin: 0 0 10px 0; overflow: hidden; } img { float: left; }</style>
Floating parent element at the same time
"Same stream and pollution" also float the parent element. after a floating section, no matter whether other child elements are floating or not, it will closely enclose (contract) all its child elements. Therefore, you need to set the width so that the section is the same as the width of the view. besides, because the section is floating, footer tries to squeeze it up. to force footer to stay under section, clear floating effects for footer. the cleared element is not promoted to the side of the floating element.
<style> section { border: 1px solid blue; margin: 0 0 10px 0; /*overflow: hidden;*/ float: left; width: 100%; } img { float: left; } footer { clear: left; border: 1px solid red; } </style>
Add non-floating clear elements
For the parent ElementLastAdd a non-floating child element and clear the child element. the pseudo element is used again. after inserts a pseudo element after the element content rather than after the element.
<section class = "clearfix">
.clearfix:after {content: ".";display: block;height: 0;visibility: hidden;clear: both;}