css彈性佈局程式碼例項

antzone發表於2017-03-24

分享一段程式碼例項,它演示了css3的彈性佈局功能。

程式碼例項如下:

[HTML] 純文字檢視 複製程式碼
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>螞蟻部落</title>
<style>
.warp {
  width: 200px;
  height: 200px;
  background-color: #000;
  margin: 100px auto;
  border-radius: 20px;
  display: flex;
  justify-content: space-between;
  padding: 15px;
}
.left {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.content {
  display: flex;
  justify-content: center;
  flex-direction: column;
}
.right {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.left div, .content div, .right div {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background-color: #fff;
  text-align: center;
  line-height: 50px;
}
</style>
</head>
<body>
  <div class="warp">
    <div class="left">
      <div class="div1">1</div>
      <div class="div2">2</div>
    </div>
    <div class="content">
      <div class="div3">3</div>
    </div>
    <div class="right">
      <div class="div4">4</div>
      <div class="div5">5</div>
    </div>
  </div>
</body>
</html>

關於彈性佈局可以參閱css3 Flex彈性佈局基本語法介紹一章節。

相關文章