我知道我可以通过使用 for 循环或类似的东西以困难的方式做到这一点,但我要问
如果:有任何简单的方法可以将每 5 个图像包装在一个长图像列表中
谢谢
最佳答案
用另一个元素“包裹”图像:
是的,它非常简单:
// document.ready
$(function(){
$("#yourList img:nth-child(5)").wrap("<div class='image-wrapper'></div>");
});
将每五个图像强制放到下一行
// document.ready
$(function(){
$("#yourList img:nth-child(5)").css('clear','left');
});
这也可以在 CSS 中完成,但并非所有浏览器都支持 nth-child
:
#yourList img:nth-child(5){
clear: left;
}
关于javascript - jquery如何包装每五个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2018064/