罗田县升平网络工作室,一家专业从事网站建设的工作室

资讯论坛

 找回密码
 加入论坛

快捷登录

回帖中禁止出现的内容,违者将被直接永久禁止访问,删除ID处理 :1.违反法律法规 ,包括但不限于出现带有政治、色情、暴恐信息等内容;2.恶意攻击内容,包括但不限于:恶意攻击党和政府、辱骂跟帖者、攻击主题发布者、不服从论坛管理、挑衅管理者、挑战版规等;3.广告、推广内容,尤其出现带有病毒、恶意代码、广告链接等内容,包括但不限于:QQ号、文字QQ号、微信号、手机号、文字手机号、第三方网址、单位公司名称、网站名称等;4.回帖贴出该主题隐藏资源链接或其它主题隐藏资源链接的行为。
查看: 289|回复: 0

css实现两栏布局,左侧固定宽,右侧自适应的多种方法

[复制链接]

686

主题

670

帖子

800

积分

社区达人

积分
800
发表于 2021-11-21 02:57:02 | 显示全部楼层 |阅读模式
css实现两栏布局,左侧固定宽,右侧自适应的7种方法,代码如下所示:
1、利用 calc 计算宽度的方法 css代码:
  1. .box>div{height: 100%;}#box1>div{float: left;}.left1{width: 100px;background: yellow;}.right1{background: #09c;width:calc(100% - 100px);}
复制代码
dom结构:
  1. <div class=&quot;box&quot; id=&quot;box1&quot;>    <div class=&quot;left1&quot;>左侧定宽</div>    <div class=&quot;right1&quot;>右侧自适应</div></div>
复制代码
2、利用 float 配合 margin 实现 css代码:
  1. .box{overflow: hidden;height: 100px;margin: 10px 0;}.box>div{height: 100%;}.left2{float: left;background: yellow;width: 100px;}.right2{background: #09c;margin-left: 100px;}
复制代码
dom结构:
  1. <div class=&quot;box&quot; id=&quot;box2&quot;>    <div class=&quot;left2&quot;>左侧定宽</div>    <div class=&quot;right2&quot;>右侧自适应</div></div>
复制代码
3、利用 float 配合 overflow 实现 css代码:
  1. .box{overflow: hidden;height: 100px;margin: 10px 0;}.box>div{height: 100%;}.left3{float: left;background: yellow;width: 100px;}.right3{background: #09c;overflow: hidden;}
复制代码
dom结构:
  1. <div class=&quot;box&quot; id=&quot;box3&quot;>    <div class=&quot;left3&quot;>左侧定宽</div>    <div class=&quot;right3&quot;>右侧自适应</div></div>
复制代码
4、利用 position:absolute 配合 margin 实现
css代码:
  1. .box{overflow: hidden;height: 100px;margin: 10px 0;}.box>div{height: 100%;}#box4{position: relative;}.left4{position: absolute;left: 0;top:0;width: 100px;background: yellow;}.right4{margin-left:100px;background: #09c;}
复制代码
dom结构:
  1. <div class=&quot;box&quot; id=&quot;box4&quot;>    <div class=&quot;left4&quot;>左侧定宽</div>    <div class=&quot;right4&quot;>右侧自适应</div></div>
复制代码
5、利用 position:absolute 实现
css代码:
  1. .box{overflow: hidden;height: 100px;margin: 10px 0;}.box>div{height: 100%;}#box5{position: relative;}.left5{position: absolute;left: 0;top:0;width: 100px;background: yellow;}.right5{position: absolute;left: 100px;top:0;right: 0;width: 100%;background: #09c;}
复制代码
dom结构:
  1. <div class=&quot;box&quot; id=&quot;box5&quot;>    <div class=&quot;left5&quot;>左侧定宽</div>    <div class=&quot;right5&quot;>右侧自适应</div></div>
复制代码
6、利用 display: flex 实现
css代码:
  1. .box{overflow: hidden;height: 100px;margin: 10px 0;}.box>div{height: 100%;}#box6{display: flex;display: -webkit-flex;}.left6{flex:0 1 100px;background: yellow;}.right6{flex:1;background: #09c;}
复制代码
dom结构:
  1. <div class=&quot;box&quot; id=&quot;box6&quot;>    <div class=&quot;left6&quot;>左侧定宽</div>    <div class=&quot;right6&quot;>右侧自适应</div></div>
复制代码
7、利用 display: table 实现 css代码:
  1. .box{overflow: hidden;height: 100px;margin: 10px 0;}.box>div{height: 100%;}#box7{display: table;width: 100%;}#box7>div{display: table-cell;}.left7{width: 100px;background: yellow;}.right7{background: #09c;}
复制代码
dom结构:
  1. <div class=&quot;box&quot; id=&quot;box7&quot;>    <div class=&quot;left7&quot;>左侧定宽</div>    <div class=&quot;right7&quot;>右侧自适应</div></div>
复制代码
到此这篇关于css实现两栏布局,左侧固定宽,右侧自适应的7中方法的文章就介绍到这了,更多相关css两栏布局内容请搜索脚本之家以前的文章或继续浏览下面的相关文章,希望大家以后多多支持脚本之家!

来源:http://www.jb51.net/css/784590.html
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
打赏鼓励一下!
回复

使用道具 举报

回帖中禁止出现的内容,违者将被直接永久禁止访问,删除ID处理 :1.违反法律法规 ,包括但不限于出现带有政治、色情、暴恐信息等内容;2.恶意攻击内容,包括但不限于:恶意攻击党和政府、辱骂跟帖者、攻击主题发布者、不服从论坛管理、挑衅管理者、挑战版规等;3.广告、推广内容,尤其出现带有病毒、恶意代码、广告链接等内容,包括但不限于:QQ号、文字QQ号、微信号、手机号、文字手机号、第三方网址、单位公司名称、网站名称等;4.回帖贴出该主题隐藏资源链接或其它主题隐藏资源链接的行为。

浏览排行

(38463)2019-11-5 公共云钱包资金盘骗局揭秘: 网络传销+原始股骗局合体!

(22233)2019-12-20 12月17日 邓智天法院直播庭审疑问全解答!

(20722)2019-12-1 环保币GEC资金盘骗局最新消息: 即将崩盘!

(17244)2019-11-9 巨胸肥臀大长腿,嫩模糯美子真人COS不知火舞福利污图

(15868)2018-12-24 罗田县人民法院公布【第五批失信被执行人名单】 ...

(14972)2019-11-3 曝光!PTFX已经崩盘跑路,投资者血流成河!

(13018)2019-8-7 湖北电力网上缴费,支付宝绑定户号的初始密码是什么?

(12480)2018-10-17 罗田县人民政府“12345”市民服务热线服务指南

(11170)2019-12-11 公安定性了, 趣码是非法传销! 趣码怎么退回365元?

(11081)2019-12-15 满足你对女同事的幻想 风骚秘书阿朱销魂眼神勾魂摄魄

最新发表

[升平网络工作室]2025-8-23 [2025-08-23]罗田天气预报

[升平网络工作室]2025-8-23 西藏自治区成立60周年庆祝大会隆重举行 习近平出席大会

[升平网络工作室]2025-8-23 县委委员会召开查摆问题整改整治情况汇报会

[爱查小程序]2025-8-22 [爱查]在线听音乐操作说明

[升平网络工作室]2025-8-22 [2025-08-22]罗田天气预报

[升平网络工作室]2025-8-22 习近平率中央代表团抵达拉萨出席西藏自治区成立60周年庆祝活动

[升平网络工作室]2025-8-22 县关工委联合经济开发区开展“情系学子”助学活动 助力职工子女圆梦大学

[升平网络工作室]2025-8-21 2025年罗田县卫健系统赴高校公开招聘事业单位工作人员拟聘用人员公示公告

[升平网络工作室]2025-8-21 [2025-08-21]罗田天气预报

[升平网络工作室]2025-8-21 县安防委2025年度第三次全体(扩大)会召开

QQ|Archiver|手机版|小黑屋|资讯论坛BBS.SPW8.CN ( 鄂ICP备2021011341号-3 )|网站地图


手机扫一扫继续访问
[免责声明]
本站系本网编辑转载,转载目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责。
如涉及作品内容、版权和其它问题,请在30日内与本网联系,我们将在第一时间删除内容!
[声明]本站文章版权归原作者所有 内容为作者个人观点 本站只提供参考并不构成任何投资及应用建议。

进入社区 | 发表新帖 | 百度收录 |
技术提供:罗田县升平网络工作室
站长Email:admin@spw8.cn
投诉电话(刮开查看):15374567400

GMT+8, 2025-8-23 17:02 , Processed in 0.312344 second(s), 30 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表