你不知道的CSS妙用,纯CSS实现炫酷照片墙

演示地址:https://www.albertyy.com/2020/6/photo.html

原始效果:

鼠标经过效果:

鼠标点击效果:

代码:


   
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>纯CSS实现照片墙</title>
  6. <style>
  7. /*
  8. *纯CSS实现照片墙:
  9. *公众号:AlbertYang
  10. */
  11. /* RESET */
  12. * {
  13. margin: 0;
  14. padding: 0;
  15. }
  16. body {
  17. font-family: Tahoma, Helvetica, "\5b8b\4f53", "Arial", sans-serif;
  18. font-size: 12px;
  19. color: #eeeeee;
  20. }
  21. .container {
  22. width: 90%;
  23. height: auto;
  24. margin: 6.25rem auto;
  25. display: flex;
  26. flex-direction: row;
  27. flex-wrap: wrap;
  28. }
  29. .container .img-wrap {
  30. padding: 10px;
  31. margin: 10px;
  32. background: white;
  33. border: 1px solid #ddd;
  34. width: 160px;
  35. height: fit-content;
  36. box-shadow: 2px 2px 3px rgba(50, 50, 50, 0.4);
  37. -webkit-transition: all 0.5s ease-in;
  38. -moz-transition: all 0.5s ease-in;
  39. -ms-transition: all 0.5s ease-in;
  40. -o-transition: all 0.5s ease-in;
  41. transition: all 0.5s ease-in;
  42. z-index: 1;
  43. -webkit-filter: blur(1px);
  44. -moz-filter: blur(1px);
  45. -ms-filter: blur(1px);
  46. -o-filter: blur(1px);
  47. filter: blur(1px);
  48. }
  49. .container .img-wrap img {
  50. max-width: 100%;
  51. height: auto;
  52. }
  53. .container .img-wrap:after {
  54. content: attr(data-title);
  55. display: block;
  56. text-align: center;
  57. font-size: 15px;
  58. color: #FCC688;
  59. }
  60. .container .img-wrap:nth-child(1n) {
  61. transform: rotate(-5deg);
  62. -webkit-transform: rotate(-5deg);
  63. }
  64. .container .img-wrap:nth-child(2n) {
  65. transform: rotate(-20deg);
  66. -webkit-transform: rotate(-20deg);
  67. }
  68. .container .img-wrap:nth-child(3n) {
  69. transform: rotate(5deg);
  70. -webkit-transform: rotate(5deg);
  71. }
  72. .container .img-wrap:nth-child(4n) {
  73. transform: rotate(-10deg);
  74. -webkit-transform: rotate(-10deg);
  75. }
  76. .container .img-wrap:nth-child(5n) {
  77. transform: rotate(-30deg);
  78. -webkit-transform: rotate(-30deg);
  79. }
  80. .container .img-wrap:nth-child(6n) {
  81. transform: rotate(20deg);
  82. -webkit-transform: rotate(20deg);
  83. }
  84. .container .img-wrap:nth-child(7n) {
  85. transform: rotate(50deg);
  86. -webkit-transform: rotate(50deg);
  87. }
  88. .container .img-wrap:nth-child(8n) {
  89. transform: rotate(5deg);
  90. -webkit-transform: rotate(5deg);
  91. }
  92. .container .img-wrap:nth-child(9n) {
  93. transform: rotate(15deg);
  94. -webkit-transform: rotate(15deg);
  95. }
  96. .container .img-wrap:nth-child(10n) {
  97. transform: rotate(-15deg);
  98. -webkit-transform: rotate(-15deg);
  99. }
  100. .container .img-wrap:nth-child(11n) {
  101. transform: rotate(-25deg);
  102. -webkit-transform: rotate(-25deg);
  103. }
  104. .container .img-wrap:hover {
  105. box-shadow: 15px 15px 20px rgba(50, 50, 50, 0.4);
  106. transform: rotate(0deg) scale(1.50);
  107. -webkit-transform: rotate(0deg) scale(1.50);
  108. z-index: 2;
  109. position: relative;
  110. -webkit-filter: blur(0px);
  111. -moz-filter: blur(0px);
  112. -ms-filter: blur(0px);
  113. -o-filter: blur(0px);
  114. filter: blur(0px);
  115. cursor: pointer;
  116. }
  117. .container .img-wrap:active {
  118. background: rgba(50, 50, 50, 0.3);
  119. box-shadow: none;
  120. border: none;
  121. width: 100%;
  122. height: 100%;
  123. margin: auto;
  124. text-align: center;
  125. align-items: center;
  126. transform: rotate(0deg) translate(-50%, -50%);
  127. -webkit-transform: rotate(0deg) translate(-50%, -50%);
  128. -webkit-filter: blur(0px);
  129. -moz-filter: blur(0px);
  130. -ms-filter: blur(0px);
  131. -o-filter: blur(0px);
  132. filter: blur(0px);
  133. position: absolute;
  134. z-index: 3;
  135. left: 50%;
  136. top: 50%;
  137. cursor: zoom-in;
  138. }
  139. .container .img-wrap:active img {
  140. align-items: center;
  141. max-height: 600px;
  142. margin-top: 10%;
  143. }
  144. </style>
  145. </head>
  146. <body>
  147. <div class="container">
  148. <div class="img-wrap" data-title="照片1"><img src="http://dingyue.nosdn.127.net/3dI3RPSOI2eBbguqAvd3Tt8qeDZqVfBAIn2RRFktrpNe91512439810577.jpg"></div>
  149. <div class="img-wrap" data-title="照片2"><img src="http://01.minipic.eastday.com/20170207/20170207145729_d643e7de3fcaf066fe54e19b3293e074_4.jpeg"></div>
  150. <div class="img-wrap" data-title="照片3"><img src="https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=335766965,268232045&fm=26&gp=0.jpg"></div>
  151. <div class="img-wrap" data-title="照片4"><img src="https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=1119298312,2521482562&fm=26&gp=0.jpg"></div>
  152. <div class="img-wrap" data-title="照片5"><img src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1592929071799&di=41e3159489c46603fbcc0525675ad915&imgtype=0&src=http%3A%2F%2Fimg0.imgtn.bdimg.com%2Fit%2Fu%3D3956123290%2C3155232422%26fm%3D214%26gp%3D0.jpg"></div>
  153. <div class="img-wrap" data-title="照片6"><img src="http://dingyue.nosdn.127.net/3dI3RPSOI2eBbguqAvd3Tt8qeDZqVfBAIn2RRFktrpNe91512439810577.jpg"></div>
  154. <div class="img-wrap" data-title="照片7"><img src="http://01.minipic.eastday.com/20170207/20170207145729_d643e7de3fcaf066fe54e19b3293e074_4.jpeg"></div>
  155. <div class="img-wrap" data-title="照片8"><img src="https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=335766965,268232045&fm=26&gp=0.jpg"></div>
  156. <div class="img-wrap" data-title="照片9"><img src="https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=1119298312,2521482562&fm=26&gp=0.jpg"></div>
  157. <div class="img-wrap" data-title="照片10"><img src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1592929071799&di=41e3159489c46603fbcc0525675ad915&imgtype=0&src=http%3A%2F%2Fimg0.imgtn.bdimg.com%2Fit%2Fu%3D3956123290%2C3155232422%26fm%3D214%26gp%3D0.jpg"></div>
  158. <div class="img-wrap" data-title="照片1"><img src="http://dingyue.nosdn.127.net/3dI3RPSOI2eBbguqAvd3Tt8qeDZqVfBAIn2RRFktrpNe91512439810577.jpg"></div>
  159. <div class="img-wrap" data-title="照片2"><img src="http://01.minipic.eastday.com/20170207/20170207145729_d643e7de3fcaf066fe54e19b3293e074_4.jpeg"></div>
  160. <div class="img-wrap" data-title="照片3"><img src="https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=335766965,268232045&fm=26&gp=0.jpg"></div>
  161. <div class="img-wrap" data-title="照片4"><img src="https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=1119298312,2521482562&fm=26&gp=0.jpg"></div>
  162. <div class="img-wrap" data-title="照片5"><img src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1592929071799&di=41e3159489c46603fbcc0525675ad915&imgtype=0&src=http%3A%2F%2Fimg0.imgtn.bdimg.com%2Fit%2Fu%3D3956123290%2C3155232422%26fm%3D214%26gp%3D0.jpg"></div>
  163. <div class="img-wrap" data-title="照片6"><img src="http://dingyue.nosdn.127.net/3dI3RPSOI2eBbguqAvd3Tt8qeDZqVfBAIn2RRFktrpNe91512439810577.jpg"></div>
  164. <div class="img-wrap" data-title="照片7"><img src="http://01.minipic.eastday.com/20170207/20170207145729_d643e7de3fcaf066fe54e19b3293e074_4.jpeg"></div>
  165. <div class="img-wrap" data-title="照片8"><img src="https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=335766965,268232045&fm=26&gp=0.jpg"></div>
  166. <div class="img-wrap" data-title="照片9"><img src="https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=1119298312,2521482562&fm=26&gp=0.jpg"></div>
  167. <div class="img-wrap" data-title="照片10"><img src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1592929071799&di=41e3159489c46603fbcc0525675ad915&imgtype=0&src=http%3A%2F%2Fimg0.imgtn.bdimg.com%2Fit%2Fu%3D3956123290%2C3155232422%26fm%3D214%26gp%3D0.jpg"></div>
  168. </div>
  169. </body>
  170. </html>

文章来源: albertyang.blog.csdn.net,作者:Albert Yang,版权归原作者所有,如需转载,请联系作者。

原文链接:albertyang.blog.csdn.net/article/details/106934982

(完)