詳細介紹CSS之三欄布局的執行個體

來源:互聯網
上載者:User
1. 通過float left 和相對width實現

<!DOCTYPE html><html><head><meta charset="UTF-8"><title>css三欄布局之float left與 相對width</title><style>.block1,.block2,.block3{float:left;width:32%;height:50px;border:1px dashed #F00;margin:2px;}.block1{background-color:red;}.block2{background-color:blue;}.block3{background-color:#ffe6b8;}</style></head><body><p class="block1">block1</p><p class="block2">block2</p><p class="block3">block3</p></body></html>


2.絕對位置,通過absolute 定位使其脫離文檔流,可以自適應定義三欄寬度

<!DOCTYPE html><html>    <head>        <meta charset="UTF-8">        <title>三欄布局css之絕對位置</title>        <style>            .left,.right{width: 200px;height: 200px; position: absolute;}            .left{left:10px;background-color: red;}            .right{right:10px;background-color: blue;}            .center{margin:2px 210px ;background-color: yellow;height: 200px; }        </style>    </head>    <body>        <p class= "left">left</p>        <p class = "right">right</p>        <p class = "center">center</p>    </body></html>

3.使用自身浮動,float left 和float right

<!DOCTYPE html><html>    <head>        <meta charset="UTF-8">        <title>三欄布局css之使用自身浮動</title>        <style>            .left,.right{width: 200px;height: 200px;}            .left{float:left;background-color: red;}            .right{float:right;background-color: blue;}            .center{margin:2px 210px ;background-color: yellow;height: 200px; }        </style>    </head>    <body>        <p class= "left">left</p>        <p class = "right">right</p>        <p class = "center">center</p>    </body></html>

相關文章

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.