純CSS實現三列布局(兩邊固定,中間自適應)


看了一些網上的案例,感覺較繁雜,於是,自己整理了一篇來說明這個東西。

也是給我自己復習吧,以前有人問道,我還沒答上來呢。==

看代碼:

html:

1 <div class="top">this is top</div>
2 <div class="container">
3     <div class="left">this is left</div>
4     <div class="center">this is center</div>
5     <div class="right">this is right</div>
6 </div>
7 <div class="footer">this is footer</div>

然后是CSS:

 1 .top{
 2     width: 100%;
 3     height: 40px;
 4     background-color: #cccccc;
 5 }
 6 .footer{
 7     width: 100%;
 8     height: 50px;
 9     background-color: #abdc44;
10 }
11 /*左右固定,中間自適應*/
12 /*Start*/
13 .container{
14     width: 100%;
15     height: 100%;
16     position: relative;
17 }
18 .left{
19     position: absolute;
20     left: 0;
21     top: 0;
22     width: 400px;
23     height: 800px;
24     background-color: black;
25 }
26 .center{
27     width: auto;    /*如果沒有這一句,那么,center這個div的文字就不會自動換行*/
28     margin: 0 400px;
29     height: 1000px;
30     background-color: yellow;
31 }
32 .right{
33     position: absolute;
34     top: 0;
35     right: 0;
36     width: 400px;
37     height: 900px;
38     background-color: red;
39 }
40 /*End*/    

最后是這個樣子:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM