Web前端入門學習(6)——浮動例子之鑒賞

來源:互聯網
上載者:User

標籤:執行個體   浮動   列表   

浮動例子之鑒賞

  

  在浮動原理及清除浮動一文中(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" ></li>        <li><img src="http://img.baidu.com/hi/babycat/C_0020.gif" ></li>        <li><img src="http://img.baidu.com/hi/babycat/C_0003.gif" ></li>        <li><img src="http://img.baidu.com/hi/babycat/C_0017.gif" ></li>        <li><img src="http://img.baidu.com/hi/babycat/C_0004.gif" ></li>        <li><img src="http://img.baidu.com/hi/babycat/C_0015.gif" ></li>        <li><img src="http://img.baidu.com/hi/babycat/C_0005.gif" ></li>        <li><img src="http://img.baidu.com/hi/babycat/C_0016.gif" ></li>        <li><img src="http://img.baidu.com/hi/babycat/C_0006.gif" ></li>    </ul></body></html>

顯示結果:

650) this.width=650;" src="http://s1.51cto.com/wyfs02/M01/89/84/wKioL1gWtMmxETw6AABibI9wohs972.png-wh_500x0-wm_3-wmp_4-s_1352620404.png" title="1.png" alt="wKioL1gWtMmxETw6AABibI9wohs972.png-wh_50" />

 例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>

顯示結果:

650) this.width=650;" src="http://s1.51cto.com/wyfs02/M01/89/84/wKioL1gWuuaQKy2-AAAQE5Qjqyk424.png-wh_500x0-wm_3-wmp_4-s_3642785976.png" title="2.png" alt="wKioL1gWuuaQKy2-AAAQE5Qjqyk424.png-wh_50" />

 例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>

顯示結果:

650) this.width=650;" src="http://s1.51cto.com/wyfs02/M02/89/86/wKiom1gWwPShj5IpAAAWq6ho83E436.png-wh_500x0-wm_3-wmp_4-s_3968364088.png" title="3.png" alt="wKiom1gWwPShj5IpAAAWq6ho83E436.png-wh_50" />

650) this.width=650;" src="http://img.baidu.com/hi/babycat/C_0004.gif" alt="C_0004.gif" />一般情況,一個元素裡邊所有子項目結構和樣式都是一樣,那咱們就把這看成是1個列表。以上就是這種情況。

本文出自 “小倩加油站” 部落格,請務必保留此出處http://cherry360.blog.51cto.com/12176744/1867589

Web前端入門學習(6)——浮動例子之鑒賞

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.