Analyze four common methods and principles: floating, floating embedded div, positioning, and flex. float <style type="text/css"> .wrap {background: #eee; padding: 20px; } p {margin: 0; } .left {width: 200px; height: 200px; float: left; background: coral; } .right {width: 200px; height: 200px; float: right; background: lightblue; } .middle {margin: 0 200px; background: lightpink; } </style> <div class="wrap"> <p class="left">I am on the left</p> <p class="right">I am on the right</p> <p class="middle">I was last in line, but I ran to the middle</p> </div> principle:
Floating inline div <style type="text/css"> .wrap {background: #eee; padding: 20px; } p {margin: 0; } .left {width: 200px; height: 200px; float: left; background: coral; margin-left: -100%;} .right {width: 200px; height: 200px; float: left; background: lightblue; margin-left: -200px;} .middle {width: 100%; height: 200px; float: left; background: lightpink; } span{ display: inline-block; margin: 0 200px; } </style> <div class="wrap"> <p class="middle"> <span class="inner"> I'm in the middle </p> <p class="left">I am on the left</p> <p class="right">I am on the right</p> </div> principle:
position <style type="text/css"> .wrap {background: #eee; position: relative;} p {margin: 0; } .left {width: 200px; height: 200px; background: coral; position: absolute;left: 0; top: 0;} .right {width: 200px; height: 200px; background: lightblue; position: absolute; right: 0; top: 0;} .middle {height: 200px; background: lightpink; margin: 0 200px;} </style> <div class="wrap"> <p class="middle">I am in the middle, I use margin to offset the space occupied by the two positioned elements on the left and right</p> <p class="left">I am on the left, I am a positioned element</p> <p class="right">I am on the right, I am a positioned element</p> </div> principle:
flex <style type="text/css"> .wrap {background: #eee; display: flex} p {margin: 0; } .left {width: 200px; height: 200px; background: coral; } .right {width: 200px; height: 200px; background: lightblue; } .middle {height: 200px; background: lightpink; flex: 1;} </style> <div class="wrap"> <p class="left">I am on the left</p> <p class="middle">I am in the middle, flex: 1 automatically occupies the remaining space</p> <p class="right">I am on the right</p> </div> principle:
The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. |
<<: JavaScript to achieve progress bar effect
>>: 202 Free High Quality XHTML Templates (2)
Table of contents 1. Decoupled assignment of arra...
Why do I want to organize the content in this area...
First of all, what is 404 and soft 404? 404: Simpl...
Written at the beginning I remember seeing a shar...
Table of contents 1. Install JDK 2. Install Jenki...
This article shares the installation and configur...
Whitelist rule syntax: BasicRule wl:ID [negative]...
In this experiment, we configure MySQL standard a...
In the previous article, after configuring the we...
Configure web page compression to save resources ...
Download address: https://dev.mysql.com/downloads...
The hardware requirements for deploying Hyper-V a...
Table of contents 1. What is a database? 2. Class...
Today I looked at some things related to data bac...
Create a new table CREATE TABLE `person` ( `id` i...