惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Fortinet All Blogs
Microsoft Security Blog
Microsoft Security Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Vercel News
Vercel News
Application and Cybersecurity Blog
Application and Cybersecurity Blog
C
Check Point Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
W
WeLiveSecurity
The Hacker News
The Hacker News
L
LINUX DO - 热门话题
T
Tenable Blog
Hugging Face - Blog
Hugging Face - Blog
Google Online Security Blog
Google Online Security Blog
博客园 - Franky
P
Proofpoint News Feed
H
Hacker News: Front Page
P
Privacy & Cybersecurity Law Blog
月光博客
月光博客
P
Proofpoint News Feed
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
The GitHub Blog
The GitHub Blog
云风的 BLOG
云风的 BLOG
博客园_首页
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
CERT Recently Published Vulnerability Notes
Forbes - Security
Forbes - Security
I
InfoQ
Stack Overflow Blog
Stack Overflow Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Attack and Defense Labs
Attack and Defense Labs
N
News and Events Feed by Topic
博客园 - 叶小钗
T
Threat Research - Cisco Blogs
aimingoo的专栏
aimingoo的专栏
D
Darknet – Hacking Tools, Hacker News & Cyber Security
小众软件
小众软件
大猫的无限游戏
大猫的无限游戏
MongoDB | Blog
MongoDB | Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Hacker News - Newest:
Hacker News - Newest: "LLM"
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 司徒正美
O
OpenAI News
G
Google Developers Blog
Martin Fowler
Martin Fowler
罗磊的独立博客
S
SegmentFault 最新的问题
T
Tor Project blog
量子位

博客园 - zzh

Making IE use PNG Alpha transparency C#利用短信猫收发短信息的方法 String[3]: the Size property has an invalid size of 0. - zzh XML Serializable Generic Dictionary C#中的多线程——线程同步基础 安装window service 中出现Set Service Login对话框 input style兼容IE6的方案 - zzh - 博客园 document.body.scrollTop为0的处理办法 js 获取浏览器高度和宽度值(多浏览器) Assembly Manifest 通俗简易手册 C# Enumeration 使用 关于页面的已终止操作 - zzh - 博客园 DOM标准与IE的html元素事件模型区别 访问ASP.NET临时文件夹的权限问题 打架必备!擒敌拳1-16动连贯动作 分解动作 Ajax错误提示Sys未定义解决方法 - zzh - 博客园 IE上关于PNG做背景,层上超链接不能点击的解决办法 - zzh - 博客园 解决js中onMouseOut事件冒泡的问题 javascript 中的this 与事件注册 及event
关于div高度自适应问题,兼容IE和火狐
zzh · 2011-03-02 · via 博客园 - zzh

在此,并不是指div的高度可以简单的自动调整。而是指在该div中没有置放内容的情况下,至少要保持这个div的高度为多少,而有内容的时候,又会随着内容的多少而自动调整。同时,对IE或是FF等浏览都可以兼容的。举个实例:

  div要求至少高度需要200px。也就是说,即使div中没有任何内容,高度也需要保持在200px;当DIV中的内容高度超过200px时,则该div会自动调节高度,而且又兼容各浏览嚣。怎么解决呢?

  对于初学者来说,可能想到的就是min-height:200px这个和height:auto这样的写法了。虽然这样写法用IE浏览器浏览是正常的,可是如果用火狐浏览嚣一测试一下,就知道不兼容而达不到预想的效果了。为什么会这样呢?原来是因为火狐浏览器此时不以height:auto这个执行为标准的。那要加上什么属性才可以让两个浏览器都正常去解读css呢?办法就是加上height:auto!important这个重要属性。所以答案是:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta name="Author" content="Div+CSS专业网页布局,www.divss.com" />
<meta name="keywords" content="div+css,网页布局,jpg切割布局,网页切割css,wap页面布局,网站重构" />
<title>div+css自动调整高度</title>
</head>
<body>
<div style="width:auto;height:auto!important;min-height:200px;height:200px;background-color:#f4f4f4;font-size:12px">
此层最少高度为200px,也就是说,即使div中没有任何内容,高度也会保持在200px,当DIV中的内容超过500px时,则自动增加DIV的高度。这个对IE或是FF等浏览器都会兼容的。(背景色是为了方便查看效果用的)<br />
</div>
</body>
</html>