一点flex布局的运用
电脑版发表于:2019/4/25 11:50
水平分割:
html:
<div class="flex-container"> <div class="flex-item">flex item 1</div> <div class="flex-item">flex item 2</div> <div class="flex-item">flex item 3</div> </div>
css:
<style> .flex-container { display: -webkit-flex; display: flex; -webkit-justify-content: center; justify-content: center; width: 400px; height: 250px; background-color: lightgrey; } .flex-item { background-color: cornflowerblue; width: 100px; height: 100px; margin: 10px; } </style>
水平分割,垂直居中:
html:
<div class="continer"> <div class="itemdiv"></div> <div class="itemdiv"></div> </div> <div class="continer"> <div class="itemdiv"></div> <div class="itemdiv"></div> <div class="itemdiv"></div> <div class="itemdiv"></div> </div>
css:
<style> .continer { /*width: 500px;*/ height: 100px; display: -webkit-box; flex-direction: row; -webkit-justify-content: center; display: flex; justify-content: space-around; border-bottom: 1px #ffabcd solid; background-color: #eee; } .itemdiv { border: 1px #abcdff solid; width: 50px; height: 50px; background-color: #ffabcd; /*display: flexbox;*/ margin: 20px 20px; /*垂直居中 设置上下相同的间距就可以了*/ } </style>