您可以使用#parent {
display: flex;}#narrow {
width: 200px;
background: lightblue;
/* Just so it's visible */}#wide {
flex: 1;
/* Grow to rest of container */
background: lightgreen;
/* Just so it's visible */}
Wide (rest of width)
Narrow (200px)
这基本上只是刮擦flexbox的表面。Flexbox可以做很棒的事情。
对于较旧的浏览器支持,您可以使用CSS float和width属性来解决它。#narrow {
float: right;
width: 200px;
background: lightblue;}#wide {
float: left;
width: calc(100% - 200px);
background: lightgreen;}
Wide (rest of width)
Narrow (200px)