flex彈性佈局 響應式佈局

admin發表於2019-10-18

本章節分享一段程式碼例項,它使用flex彈性佈局實現了響應式佈局效果。

更多flex彈性佈局可以參閱display:flex彈性佈局一章節。

程式碼例項如下:

[HTML] 純文字檢視 複製程式碼執行程式碼
<!DOCTYPE html>
<html> 
<head> 
<meta charset=" utf-8"> 
<meta name="author" content="http://www.softwhy.com/" /> 
<title>螞蟻部落</title> 
<style>
small{
  color:#999;
  font-weight:normal;
}
p{
  padding:10px;
  border:1px solid #FFC8C8;
  background:#FFE5E5;
  border-radius:4px;
  color:#A70000;
}
         
.demo-wrap{
  border:3px double #ddd;
  padding:10px;
}
 
.demo{
  display:flex;
  justify-content:space-between;
  align-items:flex-end;
  flex-wrap:wrap;
}
 
.demo .item{
  width:300px;
  height:120px;
  background:#444;
  line-height:50px;
  font-size:20px;
  color:#fff;
  text-align:center;
  margin-bottom:20px;
}
</style>
</head>
<body>
<div class="demo-wrap">
  <div class="demo">
    <div class="item"></div>
    <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
  </div>
</div>
</body>
</html>

上述程式碼通過彈性佈局實現了簡單的響應式效果。

相關文章