经典布局(左固定右自适应)
最简单的布局写法:
利用浮动特性,左边div固定宽度100px,右边div100%宽度。左边浮动,右边的div就会跑到左边div盒子的下面,这样就实现了左侧固定宽度,右侧自适应宽度了。装内容的话,右侧的div里再套一个div,设置margin-left:100px;。以下是代码
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style> *{padding:0;margin:0;} .all{ width:100%; } .left { float:left; width:100px; height:50px; background:greenyellow; } .right { width:100%; height:50px; background:red; } </style> </head> <body> <div class="all"> <div class="left"> left </div> <div class="right"> right </div> </div> </body> </html>
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步