我必须编写标记和 CSS,以便背景图像不会产生滚动条。只有当视口比内部内容包装器更窄时,才会创建滚动条:
对我不起作用:绝对定位的 div 在右侧导致滚动条,而左侧没有。
在固定布局中可能徒劳的尝试之一:
#background {
width: auto;
margin-left: -75px;
margin-right: -75px;
}
向左滚动无法到达位于左侧的包含块之外的区域(由于负边距)。是的!但是在窄视口的情况下,负边距会创建一个滚动条。只要 viewpart 比包含块宽,我怎么能防止滚动条?
标记:
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8" />
<title> </title>
<link rel="stylesheet" type="text/css" href="css/general.css" media="screen, projection"/>
<!--[if lte IE 7]>
<link rel="stylesheet" type="text/css" href="css/general-ie.css" media="screen"/>
<![endif]-->
</head>
<body>
<div id="page">
<img id="background" src="images/visual.jpg" alt="" />
<div id="head"><h1>Page title</h1></div><!-- /#head -->
<div id="mainpart">
<ul id="zones">
<li>
<ul>
<li class="module">Modul #1</li><!-- /#module -->
</ul>
</li>
</ul><!-- /#zones -->
<hr />
</div><!-- /#mainpart -->
<div id="foot"><h1>Footer</h1></div><!-- /#foot -->
</div><!-- /#page -->
</body>
</html>
CSS 规则:
body {
background: #000;
color: #000;
}
#page, #mainpart {
background: #fff;
}
#page {
width: 1024px;
margin: 0 auto;
position: relative;
}
#background {
position: absolute;
top: 0;
left: 0;
z-index: -1;
width: auto;
margin-left: -75px;
margin-right: -75px;
}
谁能给我一些好的建议?谢谢你。