为什么在IE浏览器里面乱码
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
html,
body {
margin: 0;
padding: 0;
}
div:not(:nth-of-type(2)) {
width: 500px;
height: 100%;
background-color: #00c4ff7a;
margin: 0 auto;
}
/*ul默认有外边距*/
ul {
width: 300px;
height: 100%;
background-color: #f9c3e6d6;
list-style: none;
/*清除默认边距*/
margin: 0;
padding: 0;
margin: 20px auto;
margin-bottom: 30px;
}
li {
width: 200px;
height: 30px;
line-height: 30px;
margin: 30px auto;
background-color: #cdffc0;
}
</style>
</head>
<body>
<div id="box">
<button id="btnAdd">添加元素</button>
<button id="btnRemove">删除元素</button>
<ul id="list">我是ul
<li>我是li1</li>
<li>我是li2</li>
<li>我是li3</li>
</ul>
</div>
<script type="text/javascript">
//此处填写代码
var list = document.getElementById('list');
var li = list.getElementsByTagName('li');
var btnAdd = document.getElementById('btnAdd');
var btnRemove = document.getElementById('btnRemove');
for(var i=0, len=li.length; i<len; i++){
li[i].onmouseover = function(){
this.style.backgroundColor="#9400ff";
}
li[i].onmouseout = function(){
this.style.backgroundColor="#EC7C7D";
}
}
btnAdd.onclick = function(){
var txt = document.createTextNode('我是li' + (li.length+1));
var newLi = document.createElement('li');
newLi.appendChild(txt);
list.appendChild(newLi);
}
btnRemove.onclick = function(){
list.removeChild(list.lastElementChild);
}
</script>
</body>
</html>
问题2:

老师的效果图里面ul是在蓝色背景垂直并水平居中的。为什么在我的ul里面有margin 上边能撑开为啥下面撑不开,并且他还是在底下?如何才能让ul在蓝色背景水平并垂直居中呢 ?我做的如下图:
11
收起
正在回答 回答被采纳积分+1
2回答


恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星