当我们在用css进行页面布局时,常常会遇到:三栏布局,两边顶宽,中间自适应且优先渲染。回想我们所接触过的qq空间,人人网等个人主页时,常常会遇到此类的布局方式,因此我们应该如何解决?
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>圣杯布局</title></head><style> *{ margin: 0; padding: 0; } h3{ color: gray; } .header{ height: 100px; margin: 0 auto; border: 2px solid black; } .footer{ height: 100px; margin: 0 auto; border: 2px solid black; } .artice{ height: 500px; margin: 15px auto; border: 2px solid black; padding-left: 250px; padding-right: 200px; } .artice .left{ background-color: paleturquoise; float: left; width: 250px; height: 500px; margin-left: -100%; position: relative; left: -250px; } .artice .right{ background-color: #ff7d8e; float: left; width: 200px; height: 500px; margin-left: -200px; position: relative; right: -200px } .artice .middle{ background-color: pink; float: left; width: 100%; height: 500px; }</style><body><div class ="header"> <h3>This is Top</h3></div><div class="artice"> <div class="middle"> <h3>This is Main</h3> </div> <div class="left"> <h3>This is left</h3> </div> <div class="right"> <h3>This is right</h3> </div></div><div class="footer"> <h3> This is L's page</h3></div></body></html>
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>双飞翼布局</title></head><style> *{ margin: 0; padding: 0; } h3{ color: gray; } .header{ height: 100px; margin: 0 auto; border: 2px solid black; } .footer{ height: 100px; margin: 0 auto; border: 2px solid black; } .artice{ height: 500px; margin: 15px auto; border: 2px solid black; /* padding-left: 250px; padding-right: 200px;*/ } .artice .left{ background-color: paleturquoise; float: left; width: 250px; height: 500px; margin-left: -100%; /* position: relative; left: -250px;*/ } .artice .right{ background-color: #ff7d8e; float: left; width: 200px; height: 500px; margin-left: -200px; /* position: relative; right: -200px*/ } .artice .middle{ background-color: pink; float: left; width: 100%; height: 500px; } .inner{ margin-left: 250px; margin-right: 200px; }</style><body><div class ="header"> <h3>This is Top</h3></div><div class="artice"> <div class="middle"> <div class="inner"> <h3>This is Main</h3> </div> </div> <div class="left"> <h3>This is left</h3> </div> <div class="right"> <h3>This is right</h3> </div></div><div class="footer"> <h3> This is L's page</h3></div></body></html>
版权声明:本文为博主原创文章,未经博主允许不得转载。
HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号