【CSS/HTML】实现可扩展性的页面布局

文章目录

前面有一篇文章讲过 《css实现两列布局,一列固定宽度,一列宽度自适应方法》,主要是讲实现一列固定宽度,一列宽度自适应的几种方法。

下面我在总结一下一般的三种扩展布局,这儿所示的扩展布局很常规,有的童鞋会说使用column或者flex啥的布局不是很方便吗,但是你也要看它的支持程度吧,比如你在手机端使用,那当然很好,那我要兼容IE8,IE9呢?

1.左右结构,左边100%;右边宽度固定

css代码:

复制代码
#header{height:80px; background:#CCC;}
#center{overflow:hidden; zoom:1;}
#main_wrapper{float:left; width:100%; margin-top:10px; margin-left:-210px;}
#main{height:200px; margin-left:210px; background:#999;}
#sidebar{float:right; width:200px; margin-top:10px; height:200px; background:#AAA;}
#footer{height:50px; margin-top:10px; background:#CCC;}

HTML代码:

复制代码
<div id="header"></div>
<div id="center">
    <div id="main_wrapper">
        <div id="main"></div>
    </div>
    <div id="sidebar"></div>
</div>
<div id="footer"></div>

2.左右结构,左边固定,右边100%

css代码:

复制代码
#header{height:80px; background:#CCC;}
#center{overflow:hidden; zoom:1;}
#sidebar{float:left; width:200px; margin-top:10px; height:200px; background:#AAA;}
#main_wrapper{float:right; width:100%; margin-top:10px; margin-left:-210px;}
#main{height:200px; margin-left:210px; background:#999;}
#footer{height:50px; margin-top:10px; background:#CCC;}

HTML代码:

复制代码
<div id="header"></div>
<div id="center">
    <div id="sidebar"></div>
    <div id="main_wrapper">
        <div id="main"></div>
    </div>
</div>

3.左中右结构,左边固定,右边固定,中间100%

css代码:

复制代码
#header{height:80px; background:#CCC;}
#center{overflow:hidden; zoom:1;}
#sidebar-l {float:left; width:200px; margin-top:10px; height:200px; background:#AAA;}
#main-wrapper {margin-top:10px; float:left; width:100%; margin-left:-420px; height:200px;}
#main {margin-left:438px; background:#999; height:200px;}
#sidebar-r {float:right; width:200px; margin-top:10px; height:200px; background:#AAA;}
#footer{height:50px; margin-top:10px; background:#CCC;}

HTML代码:

复制代码
<div id="header"></div>
<div id="center">
    <div id="sidebar-l">这里是左边</div>
    <div id="main-wrapper">
        <div id="main">这里是中间</div>
    </div>
    <div id="sidebar-r">这里是右边</div>
</div>
<div id="footer"></div>
相关推荐
aklry1 分钟前
uniapp三步完成一维码的生成
前端·vue.js
Rubin938 分钟前
判断元素在可视区域?用于滚动加载,数据埋点等
前端
爱学习的茄子9 分钟前
AI驱动的单词学习应用:从图片识别到语音合成的完整实现
前端·深度学习·react.js
用户3802258598249 分钟前
使用three.js实现3D地球
前端·three.js
程序无bug12 分钟前
Spring 面向切面编程AOP 详细讲解
java·前端
zhanshuo12 分钟前
鸿蒙UI开发全解:JS与Java双引擎实战指南
前端·javascript·harmonyos
撰卢35 分钟前
如何提高网站加载速度速度
前端·javascript·css·html
10年前端老司机41 分钟前
在React项目中如何封装一个可扩展,复用性强的组件
前端·javascript·react.js
Struggler28144 分钟前
解决setTimeout/setInterval计时不准确问题的方案
前端
sophie旭1 小时前
《深入浅出react开发指南》总结之 10.1 React运行时总览
前端·react.js·源码阅读