CSS floatLOGIN

CSS float

The attribute involved here is float, and its value can be assigned as:

left: The element floats to the left right: element floats to the right none: no floating inherit: Inherit floating properties from the parent

There is also the clear property: Mainly used to remove floating attributes in all directions (including inherited attributes)

Let’s first create a basic html and CSS file. The following is the basic content:

html:

   <div class="qd"></div>
    <div class="wd"></div>
    <div class="ed"></div>

CSS

.qd{    width: 100px;    height: 100px;    background-color: lightskyblue;
}.wd{    width: 100px;    height: 100px;    background-color: lightseagreen;
}.ed{    width: 100px;    height: 100px;    background-color: lightsalmon;
}

The following is the display effect:

QQ截图20161211183019.png

On this basis we all add float Properties, the first two go to the left, the last one to the right, see what the effect will be:

float: left;float: right;

Rendering

QQ截图20161211183117.png

Just like a few small things running in a room, you can specify the direction in which they run, and they will run to the border. For testing, we might as well limit a space for them (put all three divs into one div) ).Like this:

<div class="container">
    <div class="qd"></div>
    <div class="wd"></div>
    <div class="ed"></div>
</div>

The next thing you will see is:

QQ截图20161211183439.png

But sometimes we don’t need floats, like As shown below, we want to add a sentence below the above effect, and then we directly add a

<div class="text">hello php</div>

in the container. Then we will see

QQ截图20161211183559.png

##This shows that this div also inherits the floating attribute. If we want the font to go below, we must cancel the floating of the font div. Then we will add the following content to the CSS:

.text{    clear: both;
}

Rendering:

QQ截图20161211183809.pngNext Section

<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>浮动模型</title> <style type="text/css"> div{ border:2px red solid; width:200px; height:400px; float:left; } </style> </head> <body> <div id="div1">栏目1</div> <div id="div2">栏目2</div> </body> </html>
submitReset Code
ChapterCourseware