首页 > 代码库 > flex图片布局

flex图片布局

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>flex图片布局</title>
<style>
body {
margin: 0;
padding: 0;
}

.box {
float: left;
width: 30%;
margin-top: 10px;
margin-left: 2.5%;
height: 0;
padding-bottom: 33.98%;
background-color: #dbe0e4;
background:red;
background-size: cover;
display:block;position: relative;


}
img{

background: red;
margin: 0 auto;
max-width: 100%;
/*超出宽度的图片限制最大显示宽度
max-height:250px;
/*超出高度的图片限制最大显示高度*/
position: absolute;
top: 50%;
left: 50%;
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
</style>
</head>

<body>
<div class="box">
<img src="" >
</div>
<div class="box">
<img src="" >
</div>
<div class="box">
<img src="" >
</div>
<div class="box">
<img src="" >
</div>
<div class="box">
<img src="" >
</div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</body>

</html>

flex图片布局