css怎么设置2个div同行,第一个固定宽度,第二个占满剩余的部分?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了css怎么设置2个div同行,第一个固定宽度,第二个占满剩余的部分?相关的知识,希望对你有一定的参考价值。

css怎么设置2个div同行,第一个固定宽度

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>

body

margin:0;


.stage

position:relative;


.left

position:absolute;
left:0;
top:0;
background-color:green;
width:200px;
height:500px;


.center

margin-left:200px;
background-color:orange;
height:500px;


</style>
</head>
<body>
<div class="stage">
<div class="left"></div>
<div class="center"></div>
</div>
</body>
</html>

参考技术A

假设第一个div的宽度为200px;

设置第二个div 的width: calc(100% - 200px);

css能不能实现左边div固定宽度,右边div自适应撑满剩下的宽度

参考技术A 主内容是不能固定宽度的,不然修改游览器大小的时候主内容宽度大小不会改变,只要给需要分栏的内容设置宽度,左右是都一样的。

以上是关于css怎么设置2个div同行,第一个固定宽度,第二个占满剩余的部分?的主要内容,如果未能解决你的问题,请参考以下文章