1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
| <!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>微信朋友圈图片九宫格排版自适应(改编版)</title> <style> img { object-fit: cover; width: 100%; //max-height: 200px; } .pictures-adaptive { display: flex; flex-wrap: wrap; background-color: "#f3f5f7"; width: 66%; } .wrap { position: relative; overflow: hidden; margin-bottom: 2%; width: 100%; } .wrap:not(:nth-child(1):nth-last-child(1)) img { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; } .wrap:nth-child(1):nth-last-child(2), .wrap:nth-child(2):nth-last-child(1), .wrap:nth-child(1):nth-last-child(4), .wrap:nth-child(2):nth-last-child(3), .wrap:nth-child(3):nth-last-child(2), .wrap:nth-child(4):nth-last-child(1) { width: 49%; padding-bottom: 49%; } .wrap:nth-child(1):nth-last-child(3), .wrap:nth-child(2):nth-last-child(2), .wrap:nth-child(3):nth-last-child(1), .wrap:nth-child(n + 5), .wrap:nth-child(1):nth-last-child(n + 5), .wrap:nth-child(1):nth-last-child(n + 5) ~ .wrap { width: 32%; padding-bottom: 32%; } .wrap:nth-child(2):nth-last-child(1), .wrap:nth-child(2):nth-last-child(3), .wrap:nth-child(4):nth-last-child(1), .wrap:nth-child(2):nth-last-child(2), .wrap:nth-child(3):nth-last-child(1), .wrap:nth-child(n + 5):not(:nth-child(3n + 1)), .wrap:nth-child(1):nth-last-child(n + 5) ~ .wrap:not(:nth-child(3n + 1)) { margin-left: 2%; } </style> </head> <body> <div class="pictures-adaptive"> <div class="wrap"> <img src="/images/covers/cover_050620.jpg"> </div> <div class="wrap"> <img src="/images/covers/cover_050620.jpg"> </div> </div> </body> </html>
|