网页布局——左侧固定,右侧自适应
第一种方法:采用绝对定位
<!DOCTYPE> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style> .one { position: absolute; height: 200px; width: 300px; background-color: blue; } .two { height: 200px; margin-left: 300px; background-color: red; } </style> </head> <body> <div class="one"></div> <div class="two">第一种方法</div> </body> </html>
第二种方法:采用左浮动
SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。<!DOCTYPE> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style> .one { float:left; height: 200px; width: 300px; background-color: blue; } .two { overflow: auto; height: 200px; background-color: red; } </style> </head> <body> <div class="one"></div> <div class="two">第二种方法</div> </body> </html>
第三种方法:采用flex布局(推荐使用)
<!DOCTYPE> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no" /> <title>Document</title> <style> *{padding: 0;margin: 0;} #oo{ display: flex; flex-wrap: wrap; } .one { float:left; height: 200px; width: 200px; background-color: blue; } .two { background-color: red; flex: 1; } .three{ background-color: pink; flex: 2; } </style> </head> <body> <div id="oo"> <div class="one">1</div> <div class="two">2</div> <div class="three">3</div> </div> </body> </html>
以上转载来源:https://www.cnblogs.com/lqzweb/p/6211101.html
此外还有一种就是w3c标准提供的制作这种自适应宽度的标准方法display:table,display:table-cell;
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style> #wrap { display: table; width: 100%; } #content ,#sidebar { display:table-cell; height:240px; } #content{ background-color: blue; } #sidebar { width: 300px; background-color: #eee; } </style> </head> <body> <div id="wrap"> <div id="sidebar" >固定宽度区</div> <div id="content" >自适应区</div> </div> </body> </html>

更多精彩