html代码:
<ul class="nineUL" id="nineUL"></ul>
CSS代码:
.nineUL{display:block; overflow:hidden; width:340px; margin:20px 0 0 50px;}
.nineUL li{display:block; width:100px; height:100px; overflow:hidden; float:left; margin-right:20px;}
.nineUL li img{vertical-align:middle; width:100%;}
JS代码:
window.onload = function(){
for(var i=0; i<9; i++){
var html = "<li><img src='picture/icon/8.jpg' /></li>";
var u = document.getElementById("nineUL");
var li = document.createElement("li");
li.innerHTML = "<img src='picture/icon/8.jpg' />";
u.appendChild(li);
if(i>0 && (i%3 == 2)){
li.style.margin="0px 0px 10px 0px";
}
}
}
效果图:
![](https://video.ask-data.xyz/img.php?b=https://iknow-pic.cdn.bcebos.com/f9dcd100baa1cd11922b9abab112c8fcc2ce2d8f?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_600%2Ch_800%2Climit_1%2Fquality%2Cq_85%2Fformat%2Cf_auto)
追问![](https://video.ask-data.xyz/img.php?b=https://iknow-pic.cdn.bcebos.com/b7003af33a87e95078cdcff718385343faf2b456?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_600%2Ch_800%2Climit_1%2Fquality%2Cq_85%2Fformat%2Cf_auto)
在这个里面要怎么写?刚学这个不是太懂,如果换图片的话要在哪里更改,谢谢
追答刚学的话你可以直接用Html代码写出来,不用js。需要我写个Htm的例子给你吗?
追问那你帮我写一个吧,谢谢
追答<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
*{margin:0; padding:0; list-style:none; }
.nineUL{display:block; overflow:hidden; width:340px; margin:20px 0 0 50px;}
.nineUL li{display:block; width:100px; height:100px; overflow:hidden; float:left; margin: 10px 20px 0 0;}
.nineUL li img{vertical-align:middle; width:100%;}
.nineUL .mr0{margin-right:0px;}
</style>
</head>
<body>
<ul class="nineUL">
<li><img src='picture/icon/8.jpg' /></li>
<li><img src='picture/icon/8.jpg' /></li>
<li class="mr0"><img src='picture/icon/8.jpg' /></li>
<li><img src='picture/icon/8.jpg' /></li>
<li><img src='picture/icon/8.jpg' /></li>
<li class="mr0"><img src='picture/icon/8.jpg' /></li>
<li><img src='picture/icon/8.jpg' /></li>
<li><img src='picture/icon/8.jpg' /></li>
<li class="mr0"><img src='picture/icon/8.jpg' /></li>
</ul>
</body>
</html>
追问改图片的话,要修改哪段代码?
追答这是图片标签。src里面的内容就是图片的地址
追问谢谢,懂了
本回答被提问者和网友采纳