学无先后,达者为师

网站首页 编程语言 正文

css左侧 div给固定宽 右侧div自适应

作者:Mr_wuying 更新时间: 2022-04-11 编程语言
	<div class="left">div>
	<div class="right">div>

在这里插入图片描述

第一种 浮动

.left{
	width: 200px;
	float: left;
	height: 200px;
	background: #0000FF;
	
}
.right{
	margin-left: 200px;
	height: 200px;
	background: #00FF00;
}

弟二种 计算属性

.left{
	width: 200px;
		float: left;
		height: 200px;
		background: #0000FF;
		
	}
.right{
	width: calc(100% - 200px);
	height: 200px;
	float: right;
	background: #00FF00;
}

第三种 flex

body,html{
	width:100%;
	display: flex;
}
.left{
	flex: 0 0 200px;
	height: 200px;
	background: #0000FF;
	
}
.right{
	flex: 1;
	height: 200px;
	background: #00FF00;
}

flex:flex-grow、flex-shrink 、flex-basis
flex-grow为0,则存在剩余空间也不放大
flex-shrink为1,则空间不足该项目缩小
flex-basis为auto,则该项目本来的大小

原文链接:https://blog.csdn.net/j244233138/article/details/110139777

栏目分类
最近更新