css根据子元素多少类设置子元素的属性--九宫格
.moment-image-div:nth-child(n+1):nth-last-child(-n+9){ width: 33.33%; float: left; } .moment-image-div:nth-child(1):nth-last-child(1){ width: 100%; } .moment-image-div:nth-child(1):nth-last-child(2), .moment-image-div:nth-child(2):nth-last-child(1) { width: 50%; float: left; }
效果图:
至于高度啥的,再自行略调。