css实现自适应宽度布局

时间:2022-08-20 18:54:24

1.实现左侧宽度固定,右侧全屏自适应。

body{margin:0;padding:0}
.wrap{ width:100%; float:left}
.content{ height:300px;background:green; margin-left:200px}
.right{ width:200px; height:300px; background:red; float:left; margin-left:-100%} <body>
<div class="wrap">
<div class="content">content</div>
</div>
<div class="right">aside</div>
</body>

2.实现左侧与右侧宽度固定,中间部分全屏自适应。

<style type="text/css">
body{margin:0;padding:0}
.wrap{ width:100%; float:left}
.content{ height:300px;background:green; margin-left:200px;margin-right:200px}
.left{ width:200px; height:300px; float:left; background:yellow; margin-left:-100%}
.right{ width:200px; height:300px; background:red; float:left; margin-left:-200px}
</style> <body>
<div class="wrap">
<div class="content">content</div>
</div>
<div class="left">aside</div>
<div class="right">aside</div>
</body>