博客列表 >grid布局

grid布局

乐作人生
乐作人生原创
2020年08月26日 23:02:16579浏览
  1. 12列栅格布局: 网站首页
    html代码

    1. <body>
    2. <div class="container">
    3. <div class="row">
    4. <div class="item header col-12">
    5. <img src="./static/img/0809-logo.png" alt="logo" />
    6. <div class="sousuo">
    7. <input type="text" placeholder="输入搜索内容" />
    8. <button type="submit">搜索</button>
    9. </div>
    10. </div>
    11. </div>
    12. <div class="row">
    13. <div class="item nav col-12">
    14. <a href="" class="active">首页</a>
    15. <a href="">中医调养</a>
    16. <a href="">中药材库</a>
    17. <a href="">中药方剂</a>
    18. <a href="">中医食材</a>
    19. <a href="">中医知识</a>
    20. </div>
    21. </div>
    22. <div class="row">
    23. <div class="item banner col-12">
    24. <img src="./static/img/0809-banner.jpg" alt="banner" />
    25. </div>
    26. </div>
    27. <div class="row">
    28. <div class="item left col-3">
    29. <div class="title">
    30. <h4>中医调养</h4>
    31. <a href="">更多&gt;&gt;</a>
    32. </div>
    33. <div class="left_main">
    34. <dl>
    35. <dt><a href="">心神</a></dt>
    36. <dd>
    37. <a href="">养心安神</a>
    38. <a href="">除烦</a>
    39. <a href="">安神</a>
    40. <a href="">化痰开窍</a>
    41. <a href="">补心</a>
    42. </dd>
    43. </dl>
    44. <dl>
    45. <dt><a href="">脾胃</a></dt>
    46. <dd>
    47. <a href="">温中止泻</a>
    48. <a href="">温中止呕</a>
    49. <a href="">健胃</a>
    50. <a href="">涩肠止泻</a>
    51. <a href="">涩肠止痢</a>
    52. </dd>
    53. </dl>
    54. <dl>
    55. <dt><a href="">心神</a></dt>
    56. <dd>
    57. <a href="">养心安神</a>
    58. <a href="">除烦</a>
    59. <a href="">安神</a>
    60. <a href="">化痰开窍</a>
    61. <a href="">补心</a>
    62. </dd>
    63. </dl>
    64. <dl>
    65. <dt><a href="">脾胃</a></dt>
    66. <dd>
    67. <a href="">温中止泻</a>
    68. <a href="">温中止呕</a>
    69. <a href="">健胃</a>
    70. <a href="">涩肠止泻</a>
    71. <a href="">涩肠止痢</a>
    72. </dd>
    73. </dl>
    74. </div>
    75. </div>
    76. <div class="item right col-9">
    77. <div class="title">
    78. <h4>中药材库</h4>
    79. <a href="">更多&gt;&gt;</a>
    80. </div>
    81. <div class="right_main">
    82. <a href="">
    83. <img src="./static/img/0809-1.jpg" alt="" />
    84. <p>茯苓</p>
    85. </a>
    86. <a href="">
    87. <img src="./static/img/0809-2.jpg" alt="" />
    88. <p>茯苓</p>
    89. </a>
    90. <a href="">
    91. <img src="./static/img/0809-3.jpg" alt="" />
    92. <p>茯苓</p>
    93. </a>
    94. <a href="">
    95. <img src="./static/img/0809-4.jpg" alt="" />
    96. <p>茯苓</p>
    97. </a>
    98. <a href="">
    99. <img src="./static/img/0809-1.jpg" alt="" />
    100. <p>茯苓</p>
    101. </a>
    102. <a href="">
    103. <img src="./static/img/0809-2.jpg" alt="" />
    104. <p>茯苓</p>
    105. </a>
    106. <a href="">
    107. <img src="./static/img/0809-3.jpg" alt="" />
    108. <p>茯苓</p>
    109. </a>
    110. <a href="">
    111. <img src="./static/img/0809-4.jpg" alt="" />
    112. <p>茯苓</p>
    113. </a>
    114. </div>
    115. </div>
    116. </div>
    117. <div class="row">
    118. <div class="item footer col-12">
    119. <p>Copyright © 2020 All Rights Reserved 版权所有 杏林中医网</p>
    120. </div>
    121. </div>
    122. </div>
    123. </body>

    CSS代码

    1. * {
    2. padding: 0;
    3. margin: 0;
    4. box-sizing: border-box;
    5. }
    6. body {
    7. display: flex;
    8. /* 在主轴方向上居中对齐 */
    9. justify-content: center;
    10. /* 交叉轴上居中对齐 */
    11. align-items: center;
    12. /* 视口大小:高度100vh,宽度100vw; */
    13. min-height: 100vh;
    14. min-width: 100vw;
    15. }
    16. .container {
    17. /* min-width: 1200px; */
    18. display: grid;
    19. grid-gap: 5px;
    20. }
    21. .container > .row {
    22. display: grid;
    23. /* 默认将每一行等比例划分为12列 */
    24. grid-template-columns: repeat(12, 1fr);
    25. grid-gap: 20px;
    26. max-width: 1200px;
    27. /* min-height: 50px; */
    28. }
    29. .col-1 {
    30. grid-column: span 1;
    31. }
    32. .col-2 {
    33. grid-column: span 2;
    34. }
    35. .col-3 {
    36. grid-column: span 3;
    37. }
    38. .col-4 {
    39. grid-column: span 4;
    40. }
    41. .col-5 {
    42. grid-column: span 5;
    43. }
    44. .col-6 {
    45. grid-column: span 6;
    46. }
    47. .col-7 {
    48. grid-column: span 7;
    49. }
    50. .col-8 {
    51. grid-column: span 8;
    52. }
    53. .col-9 {
    54. grid-column: span 9;
    55. }
    56. .col-10 {
    57. grid-column: span 10;
    58. }
    59. .col-11 {
    60. grid-column: span 11;
    61. }
    62. .col-12 {
    63. grid-column: span 12;
    64. }
    65. /* 12列栅格布局 */
    66. a {
    67. text-decoration: none;
    68. color: #333;
    69. }
    70. a:hover,
    71. a:focus {
    72. color: #f00;
    73. }
    74. .header {
    75. display: grid;
    76. grid-template-columns: 2fr 1fr;
    77. place-items: start;
    78. }
    79. .header > .sousuo {
    80. display: flex;
    81. flex-flow: row nowrap;
    82. justify-content: end;
    83. align-items: center;
    84. height: 90px;
    85. width: 100%;
    86. }
    87. .header > .sousuo > input {
    88. width: 85%;
    89. height: 30px;
    90. }
    91. .header > .sousuo > button {
    92. width: 15%;
    93. height: 30px;
    94. }
    95. .nav {
    96. display: grid;
    97. grid-template-columns: 1fr 1fr 1fr 1fr 1fr 1fr 6fr;
    98. place-content: center;
    99. place-items: center;
    100. height: 40px;
    101. background-color: #f0ede6;
    102. }
    103. .nav > a.active,
    104. .nav > a:hover {
    105. color: #f00;
    106. font-weight: 700;
    107. }
    108. .banner {
    109. display: grid;
    110. grid-template-columns: 1fr;
    111. }
    112. .banner > img {
    113. width: 100%;
    114. }
    115. .left > .title,
    116. .right > .title {
    117. display: flex;
    118. flex-flow: row nowrap;
    119. justify-content: space-between;
    120. padding: 10px 0;
    121. }
    122. .left > .title > a,
    123. .right > .title > a {
    124. font-size: 14px;
    125. color: #999;
    126. }
    127. .left > .title > a:hover,
    128. .right > .title > a:hover {
    129. color: #f00;
    130. }
    131. .left_main > dl {
    132. background-color: #f0ede6;
    133. padding: 10px;
    134. margin-bottom: 20px;
    135. }
    136. .left_main > dl > dt {
    137. font-size: 14px;
    138. font-weight: 700;
    139. color: #666;
    140. margin-bottom: 10px;
    141. }
    142. .right_main {
    143. display: flex;
    144. flex-flow: row wrap;
    145. justify-content: space-between;
    146. }
    147. .right_main > a {
    148. display: flex;
    149. flex-flow: column nowrap;
    150. margin-bottom: 10px;
    151. }
    152. .right_main > a > img {
    153. width: 190px;
    154. height: 160px;
    155. }
    156. .right_main > a > p {
    157. text-align: center;
    158. padding: 5px;
    159. }
    160. .footer {
    161. display: grid;
    162. grid-template-columns: 1fr;
    163. align-items: center;
    164. background-color: #f0ede6;
    165. height: 40px;
    166. }
    167. .footer > p {
    168. text-align: center;
    169. }

  2. 响应式网络相册

    1. <style>
    2. * {
    3. padding: 0;
    4. margin: 0;
    5. box-sizing: border-box;
    6. }
    7. a {
    8. text-decoration: none;
    9. color: #333;
    10. }
    11. a:hover {
    12. color: #f00;
    13. }
    14. body {
    15. background-color: #f0ede6;
    16. }
    17. h2 {
    18. font-weight: 700;
    19. text-align: center;
    20. margin-top: 20px;
    21. }
    22. .container {
    23. /* 视口大小 */
    24. min-width: 100vw;
    25. min-height: 100vh;
    26. padding: 50px;
    27. display: grid;
    28. /* 自动填充,间接实现媒体查询 */
    29. grid-template-columns: repeat(auto-fill, 140px);
    30. grid-template-rows: repeat(auto-fill, 160px);
    31. /* 平均对齐 */
    32. place-content: space-evenly;
    33. gap: 40px 20px;
    34. }
    35. .container img {
    36. width: 100%;
    37. text-align: center;
    38. }
    39. .container > .item {
    40. background-color: #fff;
    41. padding: 10px;
    42. border-radius: 10px;
    43. /* 设置图片与文本之间的对齐关系 */
    44. display: flex;
    45. flex-flow: column nowrap;
    46. align-items: center;
    47. justify-self: center;
    48. }
    49. .item:hover {
    50. /* 鼠标移动,图片区域显示阴影 */
    51. box-shadow: 0 0 15px #000;
    52. /* 图片放大 */
    53. width: calc(100% * 1.04);
    54. }
    55. </style>
    56. <body>
    57. <h2>相册</h2>
    58. <div class="container">
    59. <div class="item">
    60. <a href=""><img src="./static/img/0809-1.jpg" alt="" /></a>
    61. <a href="">茯苓</a>
    62. </div>
    63. <div class="item">
    64. <a href=""><img src="./static/img/0809-1.jpg" alt="" /></a>
    65. <a href="">茯苓</a>
    66. </div>
    67. <div class="item">
    68. <a href=""><img src="./static/img/0809-1.jpg" alt="" /></a>
    69. <a href="">茯苓</a>
    70. </div>
    71. <div class="item">
    72. <a href=""><img src="./static/img/0809-1.jpg" alt="" /></a>
    73. <a href="">茯苓</a>
    74. </div>
    75. <div class="item">
    76. <a href=""><img src="./static/img/0809-1.jpg" alt="" /></a>
    77. <a href="">茯苓</a>
    78. </div>
    79. <div class="item">
    80. <a href=""><img src="./static/img/0809-1.jpg" alt="" /></a>
    81. <a href="">茯苓</a>
    82. </div>
    83. <div class="item">
    84. <a href=""><img src="./static/img/0809-1.jpg" alt="" /></a>
    85. <a href="">茯苓</a>
    86. </div>
    87. <div class="item">
    88. <a href=""><img src="./static/img/0809-1.jpg" alt="" /></a>
    89. <a href="">茯苓</a>
    90. </div>
    91. <div class="item">
    92. <a href=""><img src="./static/img/0809-1.jpg" alt="" /></a>
    93. <a href="">茯苓</a>
    94. </div>
    95. </div>
    96. </body>


声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议