---
title: "IE 1px的div"
author: "roc08"
date: "2011-09-15T16:24:18Z"
tags: []
categories: ["Web前端"]
slug: "ie-1px-div"
draft: false
lastmod: "2011-09-15T16:24:18Z"
id: 1172683
url: "https://roc08.iteye.com/blog/1172683"
---

在IE中默认div的大小是最小15px，若设置的div高度小于15px，比如设置为1px会发现没有效果，这是设置font-size:0px;line-height:1px;即可

```java
<html>
<body>
<div id="i1" style="border:1px solid black;height:1000px;width:800px;position:relative;"></div>
<script>
var str="";
for(var i=1,j=2;i<10;i++,j*=2){
str +='<div style="border-top:1px solid balck;font-size:0px;line-height:1px;position:absolute;top:'+(1000-j)+'px;left:'+(100*(i-1)+1)+'px;width:100px;height:'+(j-1)+'px;" bgColor:"#cccccc"></div>'
  //alert(j-1);
}
var d = document.getElementById("i1");
//d.appendChild(div);
d.innerHTML = str;

</script>
</body>
</html>
```