当前位置:主页 > 查看内容

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

发布时间:2021-04-29 00:00| 位朋友查看

简介:在最新的html标准中 有了个calc css表达式,我们可以用这个来计算布局。 但是在古老的IE中,却不支持,为了所有浏览器的支持,这里用了js来做。 截图: code: 复制代码 代码如下: !DOCTYPE HTML PUBLIC "-//IETF//DTD LEVEL1//EN" html head titleMyHtml.htm……
在最新的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>

原文链接:https://m.jb51.net/web/86789.html
本站部分内容转载于网络,版权归原作者所有,转载之目的在于传播更多优秀技术内容,如有侵权请联系QQ/微信:153890879删除,谢谢!

推荐图文


随机推荐