日期:2014-05-17  浏览次数:20638 次

CSS+DIV布局
CSS code
#Layer1 {
    position:absolute;
    width:98%;
    height:1091px;
    z-index:1;
    left: 35px;
    top: 10px;
}

想用CSS控制层宽度为整个浏览器宽度的98%,这样好像不能实现。各位有什么方法吗

------解决方案--------------------
你的意思是浏览器clientWidth减去滚动条宽度的98%?
HTML code

<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>宽度百分比</title>
<style type="text/css">
*{
    margin:0;
    padding:0;
}
#Layer1 {
    position:absolute;
    width:98%;
    height:1091px;
    z-index:1;
    left: 35px;
    top: 10px;
    background:blue;
}
</style>
</head>
<div id="Layer1"></div>
<body>
</body>
</html>

------解决方案--------------------
HTML code

<!doctype html>
<html>
<head>
<meta charset="gbk" />
<title>宽度百分比</title>
<style type="text/css">
*{
    margin:0;
    padding:0;
}

#Layer1 {
    margin:0 auto;
    width:98%;
    height:1091px;
    background:blue;
}
</style>
</head>
<div id="Layer1"></div>
<body>
</body>
</html>