【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>
相关推荐
JudithHuang1 小时前
Vue3 Vitest 单元测试进阶
前端·单元测试·log4j·vue
费曼学习法1 小时前
把 Agent 可观测性做进 Harness:从日志里只有 task finished 到全链路回放
前端
GuWenyue1 小时前
z-index 写到 9999 还是被盖住:把层叠上下文的 6 个反例全复现了一遍
前端·css·浏览器
htzyl2061 小时前
TypeScript:tsconfig配置误区及详情介绍,让你清清楚楚
前端·typescript
不服老的小黑哥1 小时前
0b · M2:服务化 + SSE 流式
前端
梦曦i1 小时前
0.9.0 新增页面级 style 支持
前端·uni-app x
不服老的小黑哥1 小时前
10a · M1:命令行 Agent
前端
疯华整猫1 小时前
类型全对、tsc 零错误,上线却白屏:AI 时代学 TypeScript,学的是它替不了的那一层
前端·typescript
Hilaku1 小时前
2027制药业4大ERP选型参考:主流厂商对比与优缺点分析
前端·javascript·程序员
不可能片场2 小时前
工程实践 管道截断让证据写不出来
前端·electron