1. 程式人生 > >第四篇部落格 CSS Grid 佈局基礎

第四篇部落格 CSS Grid 佈局基礎

wcphahaha  

CSS Grid 佈局基礎

grid 關鍵詞解釋


 

grid-template-columns: repeat(3, 1fr):

template:模板;

column:縱列;

repeat:重複;

(3, 1fr):將頁面分成3縱列、每一列寬度為1fr(fr是自適應長度單位);

 

grid-gap: 10px:間隙大小10px;     grid-auto-rows:
minmax(100px, auto); auto:自動設定; rows:每一行的長度; minmax():設定最小最大值;   grid-column: 設定元素列的區域範圍; grid-row:設定元素行的區域範圍;   程式碼例項:

  複製程式碼
.wrapper {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-gap: 10px;
  grid-auto-rows: minmax(100px, auto);
}
.one {
  grid-column: 1 / 3;
  grid-row: 1;
}
.two { 
  grid-column: 2 / 4;
  grid-row: 1 / 3;
}
.three {
  grid-column: 1;
  grid-row: 2 / 5;
}
.four {
  grid-column: 3;
  grid-row: 3;
}
.five {
  grid-column: 2;
  grid-row: 4;
}
.six {
  grid-column: 3;
  grid-row: 4;
}
.wrapper div{
  background-color: rgb(251, 205, 145);
  border: 2px solid #666;
  opacity: .7;
  border-radius :5px;
  text-align: center;
}
複製程式碼 複製程式碼
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="./class2.css">
    <title>Document</title>
</head>
<body>
<div class="wrapper">
    <div class="one">One</div>
    <div class="two">Two</div>
    <div class="three">Three</div>
    <div class="four">Four</div>
    <div class="five">Five</div>
    <div class="six">Six</div>
</div>
</body>
</html>

grid 關鍵詞解釋


 

grid-template-columns: repeat(3, 1fr):

template:模板;

column:縱列;

repeat:重複;

(3, 1fr):將頁面分成3縱列、每一列寬度為1fr(fr是自適應長度單位);

 

grid-gap: 10px:間隙大小10px;     grid-auto-rows: minmax(100px, auto); auto:自動設定; rows:每一行的長度; minmax():設定最小最大值;   grid-column: 設定元素列的區域範圍; grid-row:設定元素行的區域範圍;   程式碼例項:
  複製程式碼
.wrapper {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-gap: 10px;
  grid-auto-rows: minmax(100px, auto);
}
.one {
  grid-column: 1 / 3;
  grid-row: 1;
}
.two { 
  grid-column: 2 / 4;
  grid-row: 1 / 3;
}
.three {
  grid-column: 1;
  grid-row: 2 / 5;
}
.four {
  grid-column: 3;
  grid-row: 3;
}
.five {
  grid-column: 2;
  grid-row: 4;
}
.six {
  grid-column: 3;
  grid-row: 4;
}
.wrapper div{
  background-color: rgb(251, 205, 145);
  border: 2px solid #666;
  opacity: .7;
  border-radius :5px;
  text-align: center;
}
複製程式碼 複製程式碼
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="./class2.css">
    <title>Document</title>
</head>
<body>
<div class="wrapper">
    <div class="one">One</div>
    <div class="two">Two</div>
    <div class="three">Three</div>
    <div class="four">Four</div>
    <div class="five">Five</div>
    <div class="six">Six</div>
</div>
</body>
</html>