Blogger Information
Blog 62
fans 3
comment 1
visits 29687
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
css中grid属性基本写法和演示代码
kiraseo_wwwkiraercom
Original
373 people have browsed it

grid属性1行2列效果

演示代码

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>利用grid属性1行2列效果</title>
  8. </head>
  9. <body>
  10. <div class="box">
  11. <div class="item">1</div>
  12. <div class="item">2</div>
  13. <div class="item">3</div>
  14. <div class="item">4</div>
  15. <div class="item">5</div>
  16. <div class="item">6</div>
  17. <div class="item">7</div>
  18. <div class="item">8</div>
  19. <div class="item">9</div>
  20. </div>
  21. <style>
  22. .box{
  23. background-color: blueviolet;
  24. display: grid;
  25. grid-template-columns: repeat(3,1fr);
  26. grid-template-rows: repeat(3,1fr);
  27. }
  28. .box >.item{
  29. height: 10em;
  30. border:1px solid red ;
  31. background-color: yellow;
  32. /*从1行1列开始 横跨2行 2列*/
  33. grid-area: 1 /1 / span 2 / span 2;
  34. }
  35. </style>
  36. </body>
  37. </html>

演示效果

一列2行

利用grid属性来写简易响应式布局

演示代码

<!DOCTYPE html>

<html lang="en">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>利用grid属性来写简易响应式布局</title>
</head>

<body>
<div class="box">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<div class="item">5</div>
<div class="item">6</div>
<div class="item">7</div>
<div class="item">8</div>
<div class="item">9</div>
</div>
<style>
{
padding: 0;margin: 0;box-sizing: border-box;
}
.box{
background-color: blueviolet;
/
容器布局 /
display: grid;
/
显示生成响应式网格单元 /
grid-template-columns: repeat(3,1fr);
grid-template-rows: repeat(3,1fr);
/
行列间隙1em/
gap:1em ;
/
居中对齐方式 */
place-content: center;

  1. }
  2. .box >.item{
  3. height: 12em;
  4. background-color: yellow;
  5. /* 从1行1列开始 横跨2行 2列*/
  6. /* grid-area: 1 /1 / span 2 / span 2; */
  7. /* 排列方式规则 列表对齐 */
  8. grid-auto-flow: row;
  9. }
  10. </style>

</body>
</html>
```

演示效果图

演示效果

Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post