演示代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" type="text/css" href="reset.css"/>
<style type="text/css">
.box{
width: 400px;height: 400px;background-color: aqua;
margin: 100px auto;overflow: hidden;
display: flex;/* 转成弹性盒子 */
justify-content: space-between;/* 主轴两端对齐 */
align-content: space-between;/* 交叉轴两端对齐 */
}
.wyzx{
width: 120px;height: 50px;line-height: 50px;
background-color: red;text-align: center;color: white;
}
#n1{
background-color: #FF0000;width: 100px;
flex-shrink: 1;/* 1/6 */
}
#n2{
background-color: #00ff00;width: 200px;
flex-shrink: 2;/* 2/6 */
}
#n3{
background-color: #0000ff;width: 300px;
flex-shrink: 3;/* 3/6 */
}
</style>
</head>
<body>
<!--
设置弹性元素收缩比flex-shrink来分配剩余空间,默认值为1
多出来的尺寸
总权重:元素1尺寸*收缩比+元素2尺寸*收缩比......=总权重。比如示例中得出100+400+900=1400
单个元素收缩空间:
元素尺寸*收缩比率*多出来的尺寸/总权重
-->
<!-- ul.box>li.wyzx{我要自学$}*3 -->
<ul class="box">
<li id="n1" class="wyzx">我要自学1</li>
<li id="n2" class="wyzx">我要自学2</li>
<li id="n3" class="wyzx">我要自学3</li>
</ul>
</body>
</html>