方法一:使用box-pack的justify实现:使用display:flex弹性盒子模型实现根据窗口大小自适应宽度。代码如下:
*{
margin: 0;
padding: 0;
}
.container{
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
margin-top: 30px;
-webkit-box-pack: justify;
-webkit-justify-content: space-between;
-ms-flex-pack:justify ;
justify-content: space-between;
}
.container a{
width:20%;
display: block;
height: 50px;
line-height: 45px;
text-align: center;
border 1px solid red;
color: sandybrown;
font-size: 16px;
margin-bottom: 5px;
border-radius: 3px;
background-color: skyblue;
text-decoration: none;
}
效果如下:
方法二:使用column多列 布局实现,具体代码如下:
*{margin: 0;padding: 0;}
.container{
-webkit-column-count: 4;-moz-column-count: 4;column-count: 4;
-webkit-column-gap: 20px;-moz-column-gap: 20px;column-gap: 20px;
margin-top: 100px;
}
.container a{
display: block;
height: 50px;
line-height: 50px;
text-align: center;
border: 1px solid sandybrown;
color: #0066CC;
font-size: 16px;
margin-bottom: 5px;
border-radius: 4px;
background-color: salmon;
text-decoration: none;
}
效果如下: