代码如下:
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"> <title>flex弹性布局</title> <style type="text/css"> .extract-list { margin: 20px auto; max-width: 1030px; display: -webkit-box; display: -moz-box; display: -ms-flexbox; display: -webkit-flex; display: flex; -webkit-flex-flow: row wrap; flex-flow: row wrap; justify-content: space-between; } .extract { position: relative; margin: 0 15px 50px; -webkit-flex: 1 0 300px; -moz-flex: 1 0 300px; -ms-flex: 1 0 300px; -o-flex: 1 0 300px; flex: 1 0 300px; -webkit-align-items: stretch; align-items: stretch; border: 1px solid #eee; border-bottom-width: 2px; border-radius: 5px; background-color: #fff; display: inline-block; } .extract a { display: block; color: #999; text-decoration: none; } .extract-top { position: relative; width: 100%; height: 125px; text-align: center; border-radius: 5px 5px 0 0 ; background: #5FCF80 url(images/extract_1.jpg) no-repeat; background-size: cover; background-position: 50%; } .extract:hover .extract-top:before { content: ""; position: absolute; top: 0; left: 0; right: 0; bottom: 0; background-color: rgba(182, 192, 199, 0.45); } .extract-main { padding: 10px 20px; font-size: 16px; } .extract-main p.category { font-size: 12px; color: #ccc; } .extract-main p { font-size: 14px; } .extract-main h3 { color: #333; } </style> </head> <body> <div class="extract-list"> <div class="extract"> <a href="#"> <div class="extract-top"></div> <div class="extract-main"> <p class="category">in Category</p> <h3>标题1</h3> <div> <p>这里是内容这里是内容这里是内容这里是内容这里是内容这里是内容这里是内容这里是内容<br> 这里是内容这里是内容这里是内容这里是内容这里是内容这里是内容这里是内容这里是内容</p> <p><!--other buttons--></p> </div> </div> </a> </div> <div class="extract"> <a href="#"> <div class="extract-top"></div> <div class="extract-main"> <p class="category">in Category</p> <h3>标题1</h3> <div> <p>这里是内容这里是内容这里是内容这里是内容这里是内容这里是内容这里是内容这里是内容<br> 这里是内容这里是内容这里是内容这里是内容这里是内容这里是内容这里是内容这里是内容</p> <p><!--other buttons--></p> </div> </div> </a> </div> <div class="extract"> <a href="#"> <div class="extract-top"></div> <div class="extract-main"> <p class="category">in Category</p> <h3>标题1</h3> <div> <p>这里是内容这里是内容这里是内容这里是内容这里是内容这里是内容这里是内容这里是内容<br> 这里是内容这里是内容这里是内容这里是内容这里是内容这里是内容这里是内容这里是内容</p> <p><!--other buttons--></p> </div> </div> </a> </div> </div> </body> </html>
效果图: