方案一:利用padding-left预留空间,左侧脱标,右侧宽度相当于父元素的100%
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>左侧宽度固定,右侧宽度自适应</title> <style> .container{ padding-left: 300px; width: 100%; height: 500px; background-color: cadetblue; position: relative; } .left{ position: absolute; left: 0; top: 0; width: 300px; height: 500px; background-color: brown; } .right{ height: 500px; width: 100%; background-color: aqua; } </style> </head> <body> <div class="container"> <div class="left">left</div> <div class="right"> right right right right right </div> </div> </body> </html>
方案二:左侧设置浮动,右侧不指定宽度
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> .left{ float: left; width: 500px; height: 500px; background-color: cadetblue; } .right{ height: 500px; background-color: brown; } </style> </head> <body> <div class="left">left</div> <div class="right">right</div> </body> </html>
时间: 2024-10-01 23:11:18