Float and Clear Float in Overview Page

Float and Clear Float in Overview Page

1. Float: The main purpose is to achieve the effect of text wrapping around pictures.

It has also become the easiest way to create a multi-column layout.

 <img src="" />
<p>Text content paragraph content text content paragraph content text content paragraph content text content paragraph content text content paragraph content text content paragraph content</p>

【1】Text wrapping image

  P {margin: 0; border: solid 1px;}
  img {float: left;}

【2】Create a multi-column layout

  P {margin: 0; border: solid 1px; width: 200px; float: left;}
  img {float: left;}

2. The floating element is out of the document flow, and its parent element can't see it, because it won't surround it, so the child element will have a height, but the parent element will not be propped up, which is not what we want.

There are three solutions below. Please consider the situation and apply them appropriately:

 <section>
<img src=" />
<p>This is a paragraph. This is a paragraph. This is a paragraph. This is a paragraph. This is a paragraph. This is a paragraph. This is a paragraph.</p>
</section>
<footer>This is the bottom. This is the bottom. This is the bottom. This is the bottom. This is the bottom. This is the bottom. This is the bottom. This is the bottom.</footer>
section , footer {border: solid 1px;}
img {float: left;}

【1】Add overflow: hidden to the parent element; force the parent element to surround the floating element

The real purpose of this declaration is to prevent the parent element from being stretched by oversized content. After applying overflow: hidden, the parent element still maintains its set width, and oversized child content will be cut off by the container.

In addition, overflow: hidden has another effect, which is that it can reliably force the parent element to contain its floated child elements.

It cannot be used on the top-level element that uses the drop-down menu, otherwise the drop-down menu as its child element will not be displayed.

【2】Float the parent element at the same time, with a width of 100% the same as the browser width, and clear the float for the footer so that the footer will not be squeezed next to the section

  section {border: solid 1px; float: left; width:100%}
  footer {border: solid 1px; clear: left}
  img {float: left;}

Cannot be used on elements that are automatically centered by margins. Otherwise it is no longer centered.

【3】Add non-floating clearing elements (pseudo elements)

 .clearfix:after {
  content: "";
  display: block ;
  height: 0
  visibility: hidden;
  clear : both
}

3. How to clear when there is no parent element (img p as a group, no parent element)

 <section>
  <img src=" />
  <p class="clearfix">Text content paragraph content text content paragraph content text content paragraph content text content paragraph content text content paragraph content text content paragraph content</p>
  <img src=" />
  <p class="clearfix">Text content paragraph content text content paragraph content text content paragraph content text content paragraph content text content paragraph content text content paragraph content</p>
  <img src=" />
  <p class="clearfix">Text content paragraph content text content paragraph content text content paragraph content text content paragraph content text content paragraph content text content paragraph content</p>
</section>
.clearfix:after {
  content: "";
  display: block ;
  height: 0
   visibility: hidden;
  clear : both
}

The above is the full content of this article. I hope that the content of this article can bring some help to your study or work. At the same time, I also hope that you can support 123WORDPRESS.COM!

<<:  Server stress testing concepts and methods (TPS/concurrency)

>>:  Vue3+Element+Ts implements basic search reset and other functions of the form

Recommend

Customization Method of Linux Peripheral File System

Preface Generally speaking, when we talk about Li...

react-beautiful-dnd implements component drag and drop function

Table of contents 1. Installation 2.APi 3. react-...

Navicat for MySQL 11 Registration Code\Activation Code Summary

Recommended reading: Navicat12.1 series cracking ...

How to install MySQL database on Ubuntu

Ubuntu is a free and open source desktop PC opera...

The "3I" Standards for Successful Print Advertising

For many domestic advertisers, the creation and ev...

Vue implements two-way data binding

This article example shares the specific code of ...

Using docker command does not require sudo

Because the docker daemon needs to bind to the ho...

MySQL partitioning practice through Navicat

MySQL partitioning is helpful for managing very l...

Analysis of the process of implementing Nginx+Tomcat cluster under Windwos

Introduction: Nginx (pronounced the same as engin...

Linux system prohibits remote login command of root account

ps: Here is how to disable remote login of root a...

Summary of the Differences between find() and filter() Methods in JavaScript

Table of contents Preface JavaScript find() Metho...