運行結(jié)果:
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=yes">
- <title>通高科技</title>
- <style>
- .div {
- background-color: yellowgreen;
- width: 100px;
- height: 100px;
- border: 1px dotted black;
- margin-left: 40px;
- float: left;
- margin-top: 10px;
- }
- .div2{
- float: right;
- }
- </style>
- </head>
- <body>
- <div >
- <div class="div">左浮動1</div>
- <div class="div div2">右浮動2</div>
- <div class="div div2">右浮動3</div>
- </div>
- </body>
- </html>
向左浮動代碼表示:float: left;
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=yes">
- <title>通高科技</title>
- <style>
- .div {
- background-color: yellowgreen;
- width: 100px;
- height: 100px;
- border: 1px dotted black;
- margin-left: 40px;
- float: left;
- margin-top: 10px;
- }
- </style>
- </head>
- <body>
- <div >
- <div class="div">左浮動1</div>
- <div class="div">左浮動2</div>
- <div class="div">左浮動3</div>
- </div>
- </body>
- </html>
運行結(jié)果:
clear 屬性規(guī)定哪些元素可以在清除的元素旁邊以及在哪一側(cè)浮動。(left、right、both、none、inherit)
實例:5個左浮動
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=yes">
- <title>通高科技</title>
- <style>
- .div {
- background-color: yellowgreen;
- width: 100px;
- height: 100px;
- border: 1px dotted black;
- margin-left: 40px;
- float: left;
- }
- .div1{
- float: left;
- background-color: yellowgreen;
- width: 100px;
- height: 100px;
- border: 1px dotted black;
- margin-left: 40px;
- margin-top: 10px;
- clear: left;
- }
- </style>
- </head>
- <body>
- <div >
- <div class="div">左浮動1</div>
- <div class="div">左浮動2</div>
- <div class="div ">左浮動3</div>
- <div class="div">左浮動4</div>
- <div class="div">左浮動5</div>
- </div>
- </body>
- </html>
運行效果:
需求:對3號塊取消左浮動
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=yes">
- <title>通高科技</title>
- <style>
- .div {
- background-color: yellowgreen;
- width: 100px;
- height: 100px;
- border: 1px dotted black;
- margin-left: 40px;
- float: left;
- margin-top: 10px;
- }
- .div1{
- float: left;
- background-color: yellowgreen;
- width: 100px;
- height: 100px;
- border: 1px dotted black;
- margin-left: 40px;
- margin-top: 10px;
- clear: left;
- }
- </style>
- </head>
- <body>
- <div >
- <div class="div">左浮動1</div>
- <div class="div">左浮動2</div>
- <div class="div div1">左浮動3</div>
- <div class="div">左浮動4</div>
- <div class="div">左浮動5</div>
- </div>
- </body>
- </html>
運行結(jié)果:
對3號塊取消浮動后。3號塊沒有浮動,4號.5號塊繼續(xù)左浮動。