AutoCAD 3DMAX C语言 Pro/E UG JAVA编程 PHP编程 Maya动画 Matlab应用 Android
Photoshop Word Excel flash VB编程 VC编程 Coreldraw SolidWorks A Designer Unity3D
 首页 > 网页制作

html 左中右自适应布局(使用calc css表达式)

51自学网 http://www.51zixue.net
左中右,自适应,布局在最新的html标准中 有了个calc css表达式,我们可以用这个来计算布局。
但是在古老的IE中,却不支持,为了所有浏览器的支持,这里用了js来做。
截图:
 
code:

复制代码
代码如下:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD LEVEL1//EN">
<html>
<head>
<title>MyHtml.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script>
var left,center,right,width;
window.onload=function(){
left=$('left');
center=$('center');
right=$('right');
onresize();
};
window.onresize=function(){
try {
width = document.body.clientWidth;
center.style.width = (width - left.clientWidth - right.clientWidth - 0) + "px";
}catch(e){
//小于0会报错
}
};
function $(id){
return document.getElementById(id);
}
</script>
<style>
body,html{
height:100%;
margin:0px;
padding:0px;
overflow:hidden;
}
#left,#center,#right{
width:200px;
height:100px;
background-color:rgb(34,124,134);
float:left;
height:100%;
}
#center{
background-color:red;
}
</style>
</head>
<body>
<div id="left"></div>
<div id="center"></div>
<div id="right"></div>
</body>
</html>

左中右,自适应,布局  
上一篇:html中Div与table的区别(各方面细节探讨)  下一篇:防止别人另存为我的网页、仿制我的站点小技巧