博客列表 >1225-仿php.cn页面

1225-仿php.cn页面

世纪天城
世纪天城原创
2020年12月29日 21:53:19584浏览

项目在网格单元和容器中对齐方式

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>项目在网格单元和容器中对齐方式</title>
  8. <style>
  9. .main{
  10. width: 500px;
  11. height: 500px;
  12. margin: 0 auto;
  13. background-color: cornsilk;
  14. display: grid;
  15. grid-template-columns: 1fr 1fr 1fr;
  16. grid-template-rows: 10em;
  17. grid-auto-rows: 10em;
  18. gap: 1em;
  19. }
  20. .div{
  21. width: 3em;
  22. height: 3em;
  23. background-color: rgb(187, 247, 202);
  24. line-height: 3em;
  25. text-align: center;
  26. }
  27. /* 注:只有项目在网络单元中存在剩余空间的时候,对齐才有必要且有意义 */
  28. /* 1. 设置容器中的“所有项目”在网格单元中的对齐方式 */
  29. .main{
  30. /* place-items: 第一个值垂直方向 第二个值水平方向; */
  31. /* 垂直水平都居中 */
  32. place-items:center center;
  33. /* 垂直居上,水平居中 */
  34. /* place-items: start center; */
  35. /* 拉伸,取消项目的固定尺寸才可以看到效果 */
  36. /* place-items: stretch; */
  37. }
  38. .main{
  39. /* 只有所有项目在容器中存在剩余空间时对齐才有必要且有意义 */
  40. /* 1. 将所有项目做为一个整体在容器中对齐 */
  41. /* place-content: center center; */
  42. place-content: center;
  43. /*2. 将所有项目打散成独立个体在容器中设置对齐方式 */
  44. /* 二端对齐 */
  45. /* place-content: space-between space-between; */
  46. /* 简写 */
  47. place-content: space-between;
  48. place-content: space-around space-evenly;
  49. }
  50. /* 2. 设置容器中的“某一个项目”在网格单元中的对齐方式 */
  51. /* 这个属性必须用在项目上: place-self */
  52. .main>.div:nth-of-type(2){
  53. background-color: chartreuse;
  54. /* 居中 */
  55. place-self: center center;
  56. /* 左下 */
  57. place-self: end start;
  58. /* 右下 */
  59. place-self: end;
  60. /* 与place-self: end;相同 */
  61. place-self: end end;
  62. }
  63. </style>
  64. </head>
  65. <body>
  66. <div class="main">
  67. <div class="div">1</div>
  68. <div class="div">2</div>
  69. <div class="div">3</div>
  70. <div class="div">4</div>
  71. <div class="div">5</div>
  72. <div class="div">6</div>
  73. </div>
  74. </body>
  75. </html>

仿php.cn页面

  1. *{
  2. margin: 0;
  3. padding: 0;
  4. box-sizing: border-box;
  5. }
  6. html{
  7. font-size: 10px;
  8. background-color: rgb(245, 244, 244);
  9. }
  10. @media screen and (max-width: 1200px) {
  11. html {
  12. font-size: 16px;
  13. min-width: 1200px;
  14. }
  15. }
  16. @media screen and (max-width: 1400px) {
  17. html {
  18. font-size: 8px;
  19. min-width: 1200px;
  20. }
  21. }
  22. a{
  23. color: #cccccc;
  24. text-decoration: none;
  25. }
  26. a:hover{
  27. color: red;
  28. }
  29. ul li{
  30. display: inline-block;
  31. }
  32. header{
  33. min-height: 6em;
  34. background-color: #000;
  35. display: grid;
  36. grid-template-columns: 14em 1fr 30em;
  37. grid-template-rows: 6em;
  38. margin-bottom: 2em;
  39. }
  40. header>div:first-of-type{
  41. background-image: url('phpcn.png');
  42. }
  43. header>div:nth-of-type(2) ul{
  44. display: grid;
  45. grid-template-columns: repeat(8,1fr);
  46. grid-template-rows: 6em;
  47. gap: 1em;
  48. text-align: center;
  49. line-height: 6em;
  50. padding: 0 2em;
  51. }
  52. header>div:nth-of-type(2) ul li{
  53. font-size: 2rem;
  54. font-weight: 500;
  55. }
  56. header>div:nth-of-type(2) ul li a:hover{
  57. display: inline-block;
  58. width: 100%;
  59. height: 100%;
  60. color: #ffffff;
  61. border-bottom:5px solid seagreen;
  62. }
  63. header>div:last-of-type{
  64. display: flex;
  65. justify-content: flex-end;
  66. padding-right: 2em;
  67. align-items: center;
  68. }
  69. header>div:last-of-type .iconfont{
  70. color: white;
  71. font-size: 3rem;
  72. background-color: rgb(195, 196, 195);
  73. padding: 0.1em;
  74. border-radius: 50%;
  75. }
  76. header>div:last-of-type .iconfont:hover{
  77. color: yellow;
  78. }
  79. .container{
  80. width: 80%;
  81. margin: 0 auto;
  82. border-radius: 1em;
  83. display: grid;
  84. grid-template-columns: 22em 1fr;
  85. gap: 1em;
  86. }
  87. .container>aside{
  88. background: #2b333b;
  89. border-radius: 1em 0 0 1em;
  90. }
  91. .container>aside>ul{
  92. min-height: 100%;
  93. display: grid;
  94. grid-template-columns: 1fr;
  95. place-content: space-around space-evenly;
  96. }
  97. .container>aside>ul li{
  98. height: 3em;
  99. font-size: 2rem;
  100. padding-left: 1em;
  101. line-height: 3em;
  102. }
  103. .container>aside>ul li:hover{
  104. background-color: rgba(247, 243, 243, 0.2);
  105. }
  106. .container>main{
  107. display: grid;
  108. grid-template-columns: 1fr;
  109. grid-template-rows: 6em 1fr 12em;
  110. }
  111. .container>main>ul{
  112. background-color: #ffffff;
  113. border-radius: 0 1em 0 0;
  114. display: flex;
  115. align-items: center;
  116. justify-content: space-between;
  117. }
  118. .container>main>ul>li{
  119. font-size: 1.8rem;
  120. }
  121. .container>main>ul>li>a{
  122. color: black;
  123. }
  124. .container>main>ul>li:last-of-type{
  125. background-color: rgb(233, 232, 230);
  126. padding: 0.5em 0.5em;
  127. display: flex;
  128. align-items: center;
  129. margin-right: 1em;
  130. }
  131. .container>main>ul>li:last-of-type input{
  132. border: none;
  133. font-size: 1.8rem;
  134. }
  135. .container>main>div:first-of-type img{
  136. width: 100%;
  137. }
  138. .container>main>div:last-of-type{
  139. display: grid;
  140. grid-template-columns: 1fr 1fr 1fr 1fr;
  141. background-color: #ffffff;
  142. border-radius: 0 0 1em 0;
  143. }
  144. .container>main>div:last-of-type img{
  145. width: 100%;
  146. padding: 1em;
  147. }

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