A new beginning for div+css web page layout design (8)
Continue, when a group of floating elements encounters that there is not enough space on the right, it will automatically go down and will not leave the outermost layer. That is to say, although it will not follow the flow pattern on the ground, it will still follow the flow in the air. Pattern, ps: they all float at the same height. .
<html> <head> <style type="text/css"> body{ margin:0; padding:0; } #a{ width:500px; height:500px; border:solid; } .div{ width:100px; height:100px; border:soild; margin:5px; background:green; float:left; } #b{ width:100px; height:100px; border:soild; background:green; float:left; margin:5px; } </style> <head> <body> <div id="a"> <div id="b"></div> <div class="div"></div> <div class="div"></div> <div class="div"></div> <div class="div"></div> </div> </body> </html>
This shows the same in Firefox and IE6
What happens when the first floating div is taller than other floating divs?
<html> <head> <style type="text/css"> body{ margin:0; padding:0; } #a{ width:500px; height:500px; border:solid; } .div{ width:100px; height:100px; border:soild; margin:5px; background:green; float:left; } #b{ width:100px; height:110px; border:soild; background:green; float:left; margin:5px; } </style> <head> <body> <div id="a"> <div id="b"></div> <div class="div"></div> <div class="div"></div> <div class="div"></div> <div class="div"></div> </div> </body> </html>
You will find that the last one is stuck there. It will not squeeze through. If you squeeze it hard, it will crash, right? The div still needs to be polite, but It will also not automatically adjust the top margin to the left, because it is not that smart yet and needs to be adjusted manually. If it can run automatically, it will be a bunker, right? .
Let’s look at an example
<html> <head> <style type="text/css"> body{ margin:0; padding:0; } #a{ width:500px; height:500px; border:solid; } #b{ width:130px; height:350px; border:soild; background:green; float:left; margin:5px; } #c{ width:350px; height:350px; border:soild; background:green; float:left; margin:5px; } </style> <head> <body> <div id="a"> <div id="b"></div> <div id="c"></div> </div> </body> </html>
This is the structure of a general web page, the head is not done, here is the middle, the left is the list, and the right Display content
Now get the tail
I want to get this effect
The code is as follows
<html> <head> <style type="text/css"> body{ margin:0; padding:0; } #a{ width:500px; height:500px; border:solid; } #b{ width:130px; height:350px; border:soild; background:green; float:left; margin:5px; } #c{ width:350px; height:350px; border:soild; background:green; float:left; margin:5px; } #d{ width:490px; height:100px; border:soild; background:red; float:left; margin:5px; } </style> <head> <body> <div id="a"> <div id="b"></div> <div id="c"></div> <div id="d"></div> </div> </body> </html>
But many people forget to add float at the bottom layer :left;
That’s it
#d{ width:490px; height:100px; border:soild; background:red; margin:5px; }
The result will be like this
Remember what I said before, the div on the ground will not know the existence of the div in the sky, So I don’t know that the floating div has occupied the area.
In addition to adding float:left;
to the bottom layer, there is another way, which is clear
clear means to clear the float. I didn’t understand it at first, and probably most people don’t understand it either.
Clearing here does not mean deleting the floating div, nor does it change its position.
It should be understood this way.
Add clear to an ordinary div. , which is equivalent to installing an eye that can see the air. The div on the ground can see the situation of the div in the air, so as to know what area the div in the air occupies, so as to avoid occupying the area of the div in the air.
clear There are left right, both, and none attributes. The default is none, which means it is not set.
left means you can see the upper left space of the div on the ground itself, and right is the upper right space.
both means both sides, generally use both
<html> <head> <style type="text/css"> body{ margin:0; padding:0; } #a{ width:500px; height:500px; border:solid; } #b{ width:130px; height:350px; border:soild; background:green; float:left; margin:5px; } #c{ width:350px; height:350px; border:soild; background:green; float:left; margin:5px; } #d{ width:490px; height:100px; border:soild; background:red; margin:5px; clear:both; } </style> <head> <body> <div id="a"> <div id="b"></div> <div id="c"></div> <div id="d"></div> </div> </body> </html>
The above is the content of a new beginning of div+css web layout design (8). For more related content, please pay attention to the PHP Chinese website (www.php.cn)!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

It's out! Congrats to the Vue team for getting it done, I know it was a massive effort and a long time coming. All new docs, as well.

I had someone write in with this very legit question. Lea just blogged about how you can get valid CSS properties themselves from the browser. That's like this.

I'd say "website" fits better than "mobile app" but I like this framing from Max Lynch:

The other day, I spotted this particularly lovely bit from Corey Ginnivan’s website where a collection of cards stack on top of one another as you scroll.

If we need to show documentation to the user directly in the WordPress editor, what is the best way to do it?

There are a number of these desktop apps where the goal is showing your site at different dimensions all at the same time. So you can, for example, be writing

CSS Grid is a collection of properties designed to make layout easier than it’s ever been. Like anything, there's a bit of a learning curve, but Grid is

Questions about purple slash areas in Flex layouts When using Flex layouts, you may encounter some confusing phenomena, such as in the developer tools (d...
