Blogger Information
Blog 39
fans 0
comment 2
visits 47043
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Grid实现响应式相册与制作十二列栅格模仿华为首页
Tlilam的PHP之路
Original
1024 people have browsed it

grid制作响应式网络相册

html代码:

  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. <title>实战:响应式网络相册</title>
  7. </head>
  8. <body>
  9. <h1>跑车相册</h1>
  10. <div class="container">
  11. <div class="item box">
  12. <a href=""><img src="http://pic1.win4000.com/wallpaper/8/58ac089795b71_270_185.jpg" alt="" /></a>
  13. <a href="">法拉利812</a>
  14. </div>
  15. <div class="item">
  16. <a href=""><img src="http://pic1.win4000.com/wallpaper/c/584f5405ee753_270_185.jpg" alt="" /></a>
  17. <a href="">科尼塞克agera</a>
  18. </div>
  19. <div class="item">
  20. <a href=""><img src="http://pic1.win4000.com/wallpaper/6/584f5398e4963_270_185.jpg" alt="" /></a>
  21. <a href="">科尼塞克agera</a>
  22. </div>
  23. <div class="item">
  24. <a href=""><img src="http://pic1.win4000.com/wallpaper/f/58352b856ce36_270_185.jpg" alt="" /></a>
  25. <a href="">2016款兰博基尼</a>
  26. </div>
  27. <div class="item">
  28. <a href=""><img src="http://pic1.win4000.com/wallpaper/e/582fe7704249b_270_185.jpg" alt="" /></a>
  29. <a href="">道奇蝰蛇</a>
  30. </div>
  31. <div class="item">
  32. <a href=""><img src="http://pic1.win4000.com/wallpaper/c/5811c676042e9_270_185.jpg" alt="" /></a>
  33. <a href="">2016款布加迪</a>
  34. </div>
  35. <div class="item">
  36. <a href=""><img src="http://pic1.win4000.com/wallpaper/0/57fb03c57b7d4_270_185.jpg" alt="" /></a>
  37. <a href="">保时捷经典超跑911</a>
  38. </div>
  39. <div class="item">
  40. <a href=""><img src="http://pic1.win4000.com/wallpaper/e/57182abb1ab10_270_185.jpg" alt="" /></a>
  41. <a href="">道奇Viper ACR</a>
  42. </div>
  43. <div class="item">
  44. <a href=""><img src="http://pic1.win4000.com/wallpaper/2/57d272fcbef96_270_185.jpg" alt="" /></a>
  45. <a href="">法拉利488 </a>
  46. </div>
  47. <div class="item">
  48. <a href=""><img src="http://pic1.win4000.com/wallpaper/2/570724d3b1a42_270_185.jpg" alt="" /></a>
  49. <a href="">柯尼塞格</a>
  50. </div>
  51. </div>
  52. </body>
  53. </html>

css样式:

  1. *{
  2. padding: 0 ;
  3. margin: 0;
  4. box-sizing: border-box;
  5. }
  6. a{
  7. text-decoration: none;
  8. color: #333;
  9. }
  10. body{
  11. background-color: lightseagreen;
  12. }
  13. h1{
  14. color: white;
  15. text-align: center;
  16. font-size: 2.5rem;
  17. margin-top: 20px;
  18. text-shadow: 2px 2px 2px #333;
  19. }
  20. .container{
  21. display: grid;
  22. min-width: 100vw;
  23. min-height: 100vh;
  24. padding: 50px;
  25. /* 自动填充数量 列宽250PX 行高180px */
  26. grid-template-columns: repeat(auto-fill,280px);
  27. grid-template-rows: repeat(auto-fill,220px);
  28. /* 设置行和列的对齐方式 平均对齐 */
  29. place-content: space-evenly;
  30. /* 设置行和列间距 */
  31. gap: 30px;
  32. }
  33. /* 设置图片宽度百分百,并设置圆角5px */
  34. .container img{
  35. width: 100%;
  36. border-radius: 5px;
  37. }
  38. .container > .item{
  39. /* item背景色和 padding制造出边框效果,设置10px圆角 */
  40. background-color: #eee;
  41. padding: 10px;
  42. border-radius: 10px;
  43. /* 设置flex 处理细节 文本和图片的对齐关系 */
  44. display: flex;
  45. flex-flow: column nowrap;
  46. justify-content: center;
  47. align-items: center;
  48. /*设置整个item 鼠标图标改为手势 */
  49. cursor: pointer;
  50. }
  51. .container >.item:hover{
  52. /* 发光效果 */
  53. box-shadow: 0 0 15px #eee;
  54. /* 改变盒子宽度,制作出变大效果 */
  55. width: calc(100% * 1.02);
  56. background-color: lightcyan;
  57. }

运行效果:

grid十二栅格模仿华为首页

html代码:

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>使用flex和grid十二格模仿华为官网</title>
  5. <!-- 华为官网的图标 -->
  6. <link rel="stylesheet" type="text/css" href="https://www.huawei.com/Assets/corp/2020/css/common.css?ver=202008012338">
  7. <!-- 自定义的css样式表 -->
  8. <link rel="stylesheet" href="css/grid-huawei.css">
  9. </head>
  10. <body>
  11. <div class="top">
  12. <div>
  13. <a href=""><span class="iconfont icon-header-linkgroup-new"></span>集团网站<span class="iconfont icon-arrow-down hidden-xs hidden-sm"></span></a>
  14. <a href=""><span class="iconfont icon-header-language-new"></span>选择区域/语言<span class="iconfont icon-arrow-down hidden-xs hidden-sm"></span></a>
  15. <a href=""><span class="iconfont icon-header-login" style=""></span>登录</a>
  16. </div>
  17. </div>
  18. <header>
  19. <div><a href=""><img src="https://www-file.huawei.com/-/media/corporate/images/home/logo/huawei_logo.png"></a></div>
  20. <div>
  21. <a href="">个人及家庭产品</a>
  22. <a href="">商用产品及方案</a>
  23. <a href="">服务支持</a>
  24. <a href="">合作伙伴与开发者</a>
  25. <a href="">关于华为</a>
  26. </div>
  27. <div>
  28. <a href=""><span class="iconfont icon-bags" style="font-size: 1.2rem;" ></span><span>在线购买</span><span class="iconfont icon-arrow-down"></span> </a>
  29. <a href="" style="margin-left: 15px; "><span class="iconfont icon-search" style="font-size: 1.3rem; " ></span></a>
  30. </div>
  31. </header>
  32. <div class="slide">
  33. <div class="slideimg">
  34. <div class="mask"></div>
  35. <img src="https://www-file.huawei.com/-/media/corp2020/home/banner/2/hc2020-cn.jpg"></div>
  36. <div class="btn-group slidebox1"><a href="">了解更多</a> </div>
  37. <div class="slideprev"><a href=""><span style="color: #c7000b;font-size: 2rem;" > < </span></a></div>
  38. <div class="slidenext"><a href=""><span style="color: #c7000b;font-size: 2rem;" > > </span></a></div>
  39. <div class="pagination">
  40. <a href=""><div class="progress-div"><div></div> </div></a>
  41. <a href=""><div class="progress-div"><div></div> </div></a>
  42. <a href=""><div class="progress-div"><div></div> </div></a>
  43. </div>
  44. </div>
  45. <div class="container imgshow ">
  46. <div class="row">
  47. <!-- 12栅格 -->
  48. <div class="item col-12"><h2>推荐信息</h2></div>
  49. <!-- 84栅格 -->
  50. <div class="item col-8">
  51. <div class="mask"></div>
  52. <div class="img-box"><img src="https://www-file.huawei.com/-/media/corp2020/home/box/1/p40pro-5g-pc2.jpg"></div>
  53. <div class="text-box" >
  54. <p>华为直播</p><div class="text-box-h">智向万千,直击未来</div> <p>5G重构创造力</p>
  55. <div style="margin-bottom: -50px; padding-top: 20px;">了解更多 <span style="color: #c7000b;">></span> </div>
  56. </div>
  57. </div>
  58. <div class="item col-4">
  59. <div class="mask"></div>
  60. <div class="img-box"><img src="https://www-file.huawei.com/-/media/corp2020/banner/featured_nova7.jpg"></div>
  61. <div class="text-box" >
  62. <p>华为直播</p><div class="text-box-h">智向万千,直击未来</div> <p>5G重构创造力</p>
  63. <div style="margin-bottom: -50px; padding-top: 20px;">了解更多 <span style="color: #c7000b;">></span> </div>
  64. </div>
  65. </div>
  66. <!-- 48栅格 -->
  67. <div class="item col-4">
  68. <div class="mask"></div>
  69. <div class="img-box"><img src="https://www-file.huawei.com/-/media/corp2020/banner/matepad-pro-pc.jpg"></div>
  70. <div class="text-box" >
  71. <p>华为直播</p><div class="text-box-h">智向万千,直击未来</div> <p>5G重构创造力</p>
  72. <div style="margin-bottom: -50px; padding-top: 20px;">了解更多 <span style="color: #c7000b;">></span> </div>
  73. </div>
  74. </div>
  75. <div class="item col-8">
  76. <div class="mask"></div>
  77. <div class="img-box"><img src="https://www-file.huawei.com/-/media/corp2020/home/box/1/5g-china-tour.jpg"></div>
  78. <div class="text-box" >
  79. <p>华为直播</p><div class="text-box-h">智向万千,直击未来</div> <p>5G重构创造力</p>
  80. <div style="margin-bottom: -50px; padding-top: 20px;">了解更多 <span style="color: #c7000b;">></span> </div>
  81. </div>
  82. </div>
  83. <!-- 444栅格 -->
  84. <div class="item col-4">
  85. <div class="mask"></div>
  86. <div class="img-box"><img src="https://www-file.huawei.com/-/media/corp2020/home/box/1/huawei-live.gif"></div>
  87. <div class="text-box" >
  88. <p>华为直播</p><div class="text-box-h">智向万千,直击未来</div> <p>5G重构创造力</p>
  89. <div style="margin-bottom: -50px; padding-top: 20px;">了解更多 <span style="color: #c7000b;">></span> </div>
  90. </div>
  91. </div>
  92. <div class="item col-4">
  93. <div class="mask"></div>
  94. <div class="img-box"><img src="https://www-file.huawei.com/-/media/corp2020/home/box/1/boxbanner-pengan.jpg"></div>
  95. <div class="text-box" >
  96. <p>华为直播</p><div class="text-box-h">智向万千,直击未来</div> <p>5G重构创造力</p>
  97. <div style="margin-bottom: -50px; padding-top: 20px;">了解更多 <span style="color: #c7000b;">></span> </div>
  98. </div>
  99. </div>
  100. <div class="item col-4">
  101. <div class="mask"></div>
  102. <div class="img-box"><img src="https://www-file.huawei.com/-/media/corp2020/home/box/1/f5g.jpg"></div>
  103. <div class="text-box" >
  104. <p>华为直播</p><div class="text-box-h">智向万千,直击未来</div> <p>5G重构创造力</p>
  105. <div style="margin-bottom: -50px; padding-top: 20px;">了解更多 <span style="color: #c7000b;">></span> </div>
  106. </div>
  107. </div>
  108. </div>
  109. </div>
  110. <div class="slide">
  111. <img src="https://www-file.huawei.com/-/media/corp2020/home/sbanner/1/sbanner-pengan-cn.jpg">
  112. <div class="btn-group slidebox2"><a href="">了解更多</a> </div>
  113. </div>
  114. <div class="container">
  115. <div class="row">
  116. <!-- 12栅格 -->
  117. <div class="item col-12"><h2>新闻与活动</h2></div>
  118. <div class="item col-4 listbox " >
  119. <div class="img-box"><img src="https://www-file.huawei.com/-/media/corp2020/home/event/1/f5g2020.jpg"></div>
  120. <div class="type"><span>活动</span></div>
  121. <div class="textbox">
  122. <div class="title"> 拥抱F5G,筑新基建之“基” </div>
  123. <div class="info"> <div class="address"><span></span><span>线上直播</span></div> <div class="info"><span></span><span>2020年8月13日</span></div> </div>
  124. <div class="text">畅谈F5G时代下的新生活、新机遇</div>
  125. </div>
  126. </div>
  127. <div class="item col-4 listbox">
  128. <div class="img-box"><img src="https://www-file.huawei.com/-/media/corp2020/home/event/1/5gforgood-cn4.png"></div>
  129. <div class="type"><span>展会活动</span></div>
  130. <div class="textbox">
  131. <div class="title">
  132. 5“机”峰会 新价值 新机遇
  133. </div>
  134. <div class="info"> <div class="address"><span>线上直播</span></div> <div class="info"><span>日期</span></div> </div>
  135. <div class="text">
  136. 5G掘金五大产业机遇,<br> 联接 · 云 · AI · 计算 · 行业应用 </div>
  137. </div>
  138. </div>
  139. <div class="item col-4 listnewbox">
  140. <div class="type"><span>新闻</span></div>
  141. <div class="listnew">
  142. <a href=""><h4>全球首个FDD NR 40MHz(2.1GHz 频段)创新解决方案落地深圳,深圳电信携手华为打造5G极致体验创新试点
  143. </h4><div class="time" >2020年8月12日</div></a>
  144. <a href=""><h4>全球首个FDD NR 40MHz(2.1GHz 频段)创新解决方案</h4><div class="time" >2020年8月12日</div></a>
  145. <a href=""><h4>全球首个FDD NR 40MHz(2.1GHz 频段)创新解决方案</h4><div class="time" >2020年8月12日</div></a>
  146. <a href=""><h4>全球首个FDD NR 40MHz(2.1GHz 频段)创新解决方案</h4><div class="time" >2020年8月12日</div></a>
  147. </div>
  148. </div>
  149. <div class="item col-3"></div>
  150. <div class="item col-6 btn"><div class="btn-group"><a href="">更多活动</a> <a href="">更多新闻</a></div> </div>
  151. <div class="item col-3"></div>
  152. </div>
  153. </div>
  154. <footer>
  155. <span>©2020 华为技术有限公司</span>
  156. <span><a href="">粤A2-20044005号</a> <a href="">粤公网安备 44030702002388号</a></span> |
  157. <span><a href=""> 联系我们 </a><a href=""> 法律声明</a> <a href="">隐私保护 </a> <a href="">除名查询</a></span>
  158. </footer>
  159. </body>
  160. </html>

css代码:

  1. *{
  2. padding: 0;
  3. margin: 0;
  4. box-sizing: border-box;
  5. }
  6. a{
  7. text-decoration: none;
  8. color: rgb(51, 51, 51);
  9. }
  10. body{
  11. /* 设置flex */
  12. display: flex;
  13. /* 主轴方向为垂直 不换行 */
  14. flex-flow: column nowrap;
  15. /* 设置主轴方向居中 */
  16. justify-content: center;
  17. /* 设置侧轴方向居中 */
  18. align-items: center;
  19. font-family: "microsoft YaHei";
  20. }
  21. /*栅格代码开始*/
  22. .container{
  23. /*width: 80vw;*/
  24. width: 75vw;
  25. display: grid;
  26. /*background-color: lightcyan;*/
  27. padding: 40px 0;
  28. }
  29. .container> .row{
  30. display: grid;
  31. grid-template-columns: repeat(12,1fr);
  32. grid-gap: 20px;
  33. }
  34. .col-1{
  35. grid-column: span 1;
  36. }
  37. .col-2{
  38. grid-column: span 2;
  39. }
  40. .col-3{
  41. grid-column: span 3;
  42. }
  43. .col-4{
  44. grid-column: span 4;
  45. }
  46. .col-5{
  47. grid-column: span 5;
  48. }
  49. .col-6{
  50. grid-column: span 6;
  51. }
  52. .col-7{
  53. grid-column: span 7;
  54. }
  55. .col-8{
  56. grid-column: span 8;
  57. }
  58. .col-9{
  59. grid-column: span 9;
  60. }
  61. .col-10{
  62. grid-column: span 10;
  63. }
  64. .col-11{
  65. grid-column: span 11;
  66. }
  67. .col-12{
  68. grid-column: span 12;
  69. }
  70. /*栅格代码结束*/
  71. /* 顶部黑色小条 */
  72. .top{
  73. background-color: black;
  74. width: 100%;
  75. text-align: right;
  76. }
  77. .top a{
  78. padding-right: 25px;
  79. }
  80. .top a, .top a >span{
  81. font-size: 0.7rem;
  82. color: #ccc;
  83. line-height: 25px;
  84. }
  85. /* end */
  86. /* 导航条 */
  87. header{
  88. display: flex;
  89. justify-content: space-between;
  90. align-items: center;
  91. width: 100%;
  92. height: 79px;
  93. border-bottom: 1px solid #e6e6e6;
  94. font-size: 0.9rem;
  95. padding: 0 20px;
  96. }
  97. /* logo图片大小 */
  98. header img{
  99. height: 30px;
  100. }
  101. header > div:nth-of-type(2) >a{
  102. padding: 28px;
  103. }
  104. header > div:nth-of-type(2) >a:hover{
  105. border-bottom: 2px solid #c7000b;
  106. }
  107. /* end */
  108. /* 页脚 */
  109. footer{
  110. width: 100%;
  111. height: 50px;
  112. align-self: center;
  113. text-align: center;
  114. background-color: #e6e6e6;
  115. }
  116. footer span,a{
  117. columns: rgb(102, 102, 102);
  118. font-size: 0.8rem;
  119. }
  120. /* end */
  121. /* 轮播图设置 */
  122. /* 轮播图宽度设置 */
  123. .slide > .slideimg > img {
  124. width: 100%;
  125. }
  126. .slide{
  127. position: relative;
  128. }
  129. /*每一个轮播图了解更多按钮设置不同的定位*/
  130. .slidebox1{
  131. position: absolute;
  132. top: 70%;
  133. left:10%;
  134. }
  135. /*每一个轮播图了解更多按钮设置不同的定位*/
  136. .slidebox2{
  137. position: absolute;
  138. top: 60%;
  139. left:3%;
  140. color: white;
  141. }
  142. /* 中间横图的了解更多按钮设置 */
  143. .btn-group.slidebox2 a {
  144. color: white;
  145. padding: 10px 50px;
  146. border: 1px solid white;
  147. }
  148. /* 轮播图上一个按钮 */
  149. .slideprev{
  150. position: absolute;
  151. top: 45%;
  152. left:0;
  153. height: 50px;
  154. width: 40px;
  155. padding: 10px;
  156. display: none;
  157. }
  158. /* 轮播图下一个按钮 */
  159. .slidenext{
  160. position: absolute;
  161. top: 45%;
  162. right: 0;
  163. padding: 30px;
  164. display: none;
  165. }
  166. /* 鼠标经过轮播图显示上下页按钮 */
  167. .slideimg:hover~div{
  168. display: inline;
  169. }
  170. /* 轮播图底部三个小横条 最外层div */
  171. .pagination{
  172. position: absolute;
  173. width: 100%;
  174. text-align: center;
  175. margin: 0;
  176. bottom: 0;
  177. }
  178. /* 内层div */
  179. .progress-div{
  180. display: inline-block;
  181. margin: 0 5px;
  182. padding: 20px 0;
  183. font-size: 0.875em;
  184. }
  185. /* 横条样式 */
  186. .progress-div>div{
  187. width: 100px;
  188. height: 3px;
  189. background-color: #ccc;
  190. }
  191. /* 播放中的选中样式 */
  192. .pagination a:nth-of-type(2) > .progress-div div{
  193. background-color: #fff;
  194. }
  195. /* end */
  196. /* container imgshow 区域的样式设置 */
  197. /* 设置row里面的图片宽度百分百 */
  198. .row img{
  199. width: 100%
  200. }
  201. /*图片放大*/
  202. .row img:hover{
  203. transform: scale(1.1);
  204. }
  205. .item{
  206. position: relative;
  207. overflow: hidden;
  208. }
  209. /* imgshow第一个item 内容居中 */
  210. .imgshow .item:first-of-type{
  211. text-align: center;
  212. }
  213. .item h2{
  214. font-size: 2rem;
  215. color: #333;
  216. padding-bottom: 8px;
  217. }
  218. .item > .text-box {
  219. position: absolute;
  220. bottom: 0;
  221. left: 0;
  222. padding: 25px 30px;
  223. width: 100%;
  224. }
  225. .item > .text-box * {
  226. color: #ffffff;
  227. }
  228. .item > .text-box:hover {
  229. height: 60%;
  230. }
  231. .item > .text-box > .text-box-h {
  232. font-size: 1.2rem;
  233. font-weight: 700;
  234. }
  235. /* h2后面增加红色小横条样式 定位到h2内容下面 */
  236. .item h2:after{
  237. content: '';
  238. width: 10%;
  239. height: 2px;
  240. background-color: #c7000b;
  241. position: absolute;
  242. left: 50%;
  243. margin-left: -5%;
  244. bottom: 0;
  245. }
  246. /* 底部三栏设置 */
  247. .img-box{
  248. overflow: hidden;
  249. }
  250. /* 底部活动左上角标签 */
  251. .item >.type{
  252. padding: 7px 20px;
  253. background: url(https://www.huawei.com/Assets/corp/2020/img/exhibition/type2.png);
  254. position: absolute;
  255. top: 0;
  256. }
  257. .item >.type span{
  258. width: auto;
  259. color: #ffffff;
  260. }
  261. .item > .textbox{
  262. padding: 25px 28px 36px 28px;
  263. background-color: rgb(248,248,248);
  264. height: 30Vh;
  265. }
  266. .item > .textbox > .title{
  267. color: rgb(51, 51, 51);
  268. font-size: 1rem;
  269. font-weight: 700;
  270. margin-bottom: 5px;
  271. }
  272. .item > .textbox > .info {
  273. color: #333333;
  274. font-size: 0.9rem;
  275. margin-bottom: 20px;
  276. line-height: 20px;
  277. height: 40px;
  278. }
  279. .item > .textbox > .info > * {
  280. display: inline-block;
  281. }
  282. .item > .textbox > .text {
  283. color: #666666;
  284. font-size: 0.9rem;
  285. }
  286. /* 底部新闻 */
  287. .item.listnewbox{
  288. /*padding-top: 32px;*/
  289. background: #f8f8f8;
  290. overflow: auto;
  291. height: 390px;
  292. }
  293. .listnewbox>.listnew{
  294. padding: 32px 5px 0 5px;
  295. }
  296. .listnewbox>.listnew a{
  297. display: block;
  298. margin-bottom: 15px;
  299. }
  300. .listnewbox>.listnew a:hover h4{
  301. color: #c7000b;
  302. }
  303. /* end */
  304. /* 了解更多 更多活动 更多新闻 按钮 */
  305. .btn-group > a{
  306. display: inline-block;
  307. padding: 10px 40px;
  308. border: 1px solid black;
  309. }
  310. .btn-group > a:hover{
  311. color: #fff;
  312. background-color: #cf000b;
  313. border: 1px solid #cf000b;
  314. }
  315. .btn-group > a:last-of-type{
  316. margin-left: 10vw;
  317. }
  318. /* end */
  319. /*创建图片遮罩层*/
  320. .mask{
  321. visibility: visible;
  322. /*设置 div 元素的不透明级别:*/
  323. opacity: 1;
  324. height: 50%;
  325. width: 100%;
  326. /*content 属性与 :before 及 :after 伪元素配合使用,来插入生成内容。*/
  327. content: "";
  328. /*linear-gradient() 函数用于创建一个线性渐变的 "图像"。*/
  329. background: linear-gradient(rgba(0,0,0,0) 0%,rgba(0,0,0,0.3) 70%);
  330. display: block;
  331. top: auto;
  332. bottom: 0;
  333. position: absolute;
  334. }

运行结果:

总结

  • 使用grid布局可以很快的进行布局,十分方便,响应式方面十分好用。
  • 华为首页有些特效没有模仿出来,这些特效属于css方面,个人的经验不足,还有一些样式属性没有摸透,不太会用,css方面还需加强
Correcting teacher:天蓬老师天蓬老师

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!