
初学,搞了很久也没让1和4,6和9挨着。
可以用伸缩盒 Flex来做
你题目的解答代码如下:(如有帮助,望采纳!谢谢! 点击我这个回答右上方的【采纳】按钮)
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title> 页面名称 </title>
<style type="text/css">
.box {
display: flex;
flex-flow: column nowrap;
width: 300px;
height: 300px;
border: 3px solid #f00;
}
.box > div {
display: flex;
flex-flow: row nowrap;
justify-content: space-between;
}
.box > div:nth-child(2) {
flex-grow: 1;
align-items: center;
}
.box > div:nth-child(2) > div:nth-child(1) {
align-self: flex-start;
}
.box > div:nth-child(2) > div:nth-child(3) {
align-self: flex-end;
}
.box > div > div {
width: 70px;
height: 70px;
background-color: #f99;
}
</style>
</head>
<body>
<div class="box">
<div>
<div>1</div>
<div>2</div>
<div>3</div>
</div>
<div>
<div>4</div>
<div>5</div>
<div>6</div>
</div>
<div>
<div>7</div>
<div>8</div>
<div>9</div>
</div>
</div>
</body>
</html>