1. 程式人生 > >左邊寬度固定右邊自適應

左邊寬度固定右邊自適應

1.左側寬度固定左浮動,右側設定margin-left為左側寬度;

.box1 {
	width: 200px;
	height: 500px;
	background: #ff0;
	float: left;
}

.box2 {
	height: 500px;
	background: #f00;
	margin-left: 200px;
}

2.父級設定display:flex,左側寬度固定,右側flex為1;

.box {
	display: flex;
}

.box1 {
	width: 200px;
	height: 500px;
	background: #ff0;
}
.box2 {
    height: 500px;
	background: #f00;
	flex: 1;
}

3.左側固定寬度並絕對定位脫離文件流,右側設定margin-left;

.box1 {
	width: 200px;
	height: 500px;
	background: #ff0;
	position: absolute;
}

.box2 {
	height: 500px;
	background: #f00;
	margin-left: 200px;
}

4.左側寬度固定且左浮動,右側overflow:hidden;

.box1 {
	width: 200px;
	height: 500px;
	background: #ff0;
	float: left;
}

.box2 {
	height: 500px;
	background: #f00;
	overflow: hidden;
}