1.效果图
2.使用知识点
for循环 遍历数组 数组的增加 HTML盒子的布局 flex布局 主轴对齐方式
3.代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
/* 清除全局样式 */
*{
margin: 0;
padding: 0;
}
.box{
display: flex;
width: 700px;
height: 300px;
border-left: 1px solid black;
border-bottom: 1px solid black;
margin: 100px auto;
/* justify-content属性定义了项目在主轴上的对齐方式。 */
justify-content: space-around;
/* align-items属性定义项目在交叉轴上如何对齐。 */
align-items: flex-end;
text-align: center;
}
.box>div{
display: flex;
width: 50px;
background-color: aquamarine;
flex-direction: column;
justify-content: space-between;
}
.box div span{
margin-top: -20px;
}
.box div h4{
margin-bottom: -35px;
width: 70px;
margin-left: -10px;
}
</style>
</head>
<body>
<script>
// 输入每个属性的数值
let arr = []
for(let i = 1 ; i <= 4;i++)
{
arr.push(prompt(`请输入第${i}个属性的数值`))
}
// console.log(arr)
// 盒子开头
document.write(`<div class="box">`)
for(let i = 0 ; i<arr.length;i++)
{
document.write(`
<div style="height: ${arr[i]}px;">
<span>${arr[i]}</span>
<h4>第${i+1}属性</h4>
</div>`
)
}
// 盒子结尾
document.write(`</div>`)
</script>
</body>
</html>