您好,登錄后才能下訂單哦!
浮動例子之鑒賞
在浮動原理及清除浮動一文中(http://cherry360.blog.51cto.com/12176744/1864258),簡單介紹了浮動的相關基礎知識,為了鞏固知識點,本篇結合代碼展示關于浮動的幾個常見例子。
例1:九格子
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>九格子</title> <style> body,ul{ padding: 0; margin: 0; } .box{ width: 300px; height: 300px; margin: 100px auto; border-top: 1px solid #000; border-left: 1px solid #000; } .box li{ list-style: none; width: 99px; height: 99px; float: left; border-right: 1px solid #000; border-bottom: 1px solid #000; background: #9FC; text-align: center; line-height: 99px; } </style> </head> <body> <ul class="box"> <li><img src="http://img.baidu.com/hi/babycat/C_0002.gif" alt=""></li> <li><img src="http://img.baidu.com/hi/babycat/C_0020.gif" alt=""></li> <li><img src="http://img.baidu.com/hi/babycat/C_0003.gif" alt=""></li> <li><img src="http://img.baidu.com/hi/babycat/C_0017.gif" alt=""></li> <li><img src="https://cache.yisu.com/upload/information/20200312/65/244936.jpg" alt=""></li> <li><img src="http://img.baidu.com/hi/babycat/C_0015.gif" alt=""></li> <li><img src="http://img.baidu.com/hi/babycat/C_0005.gif" alt=""></li> <li><img src="http://img.baidu.com/hi/babycat/C_0016.gif" alt=""></li> <li><img src="http://img.baidu.com/hi/babycat/C_0006.gif" alt=""></li> </ul> </body> </html>
顯示結果:
例2:條紋
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>條紋</title> <style> body,ul{ padding: 0; margin: 0; } li{ list-style: none; } .box{ width: 500px; padding: 10px; background: #ccc; margin: 100px auto; } .box li { padding: 5px 0; height: 17px; } span{ height: 17px; float: left; } .left{ width:300px; background: yellow; } .right{ width: 200px; background: pink; } </style> </head> <body> <ul class="box"> <li> <span class="left"></span> <span class="right"></span> </li> <li> <span class="left"></span> <span class="right"></span> </li> <li> <span class="left"></span> <span class="right"></span> </li> <li> <span class="left"></span> <span class="right"></span> </li> <li> <span class="left"></span> <span class="right"></span> </li> </ul> </body> </html>
顯示結果:
例3:鋼琴按鍵
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>鋼琴按鍵</title> <style> body,ul{ margin: 0; padding: 0; } li{ list-style: none; } .list{ width: 732px; overflow: auto; border-top: 1px solid #999; border-left: 1px solid #999; margin: 100px auto; } .list li{ width: 60px; height: 180px; border-bottom: 1px solid #999; border-right: 1px solid #999; float: left; } li div { height: 100px; background: #000; color: #fff; } li .div2{ height: 50px; } </style> </head> <body> <ul class="list"> <li> <div>1</div> </li> <li> <div class="div2">2</div> </li> <li> <div>3</div> </li> <li> <div class="div2">4</div> </li> <li> <div>5</div> </li> <li> <div class="div2">6</div> </li> <li> <div>7</div> </li> <li> <div class="div2">8</div> </li> <li> <div>9</div> </li> <li> <div class="div2">10</div> </li> <li> <div>11</div> </li> <li> <div class="div2">12</div> </li> </ul> </body> </html>
顯示結果:
一般情況,一個元素里邊所有子元素結構和樣式都是一樣,那咱們就把這看成是1個列表。以上就是這種情況。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。