I have to write markup and CSS so that a background image doesn't produce a scrollbar. Only if the viewport is more narrow than the inner content wrapper, a scrollbar is created:
Doesn't work for me: Absolutely positioned div on right causing scrollbar when the left doesn't.
One of may vain attempts in a fixed layout:
#background {
width: auto;
margin-left: -75px;
margin-right: -75px;
}
An area that hang out of the containing block to the left (because of a negative margin) isn't reachable by scrolling to the left. Yes! But a negative margin-right creates a scrollbar in case of a narrow viewport. How can I prevent the scrollbar as long as the viewpart is wider than the containing block?
The markup:
<!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>
The CSS rules:
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;
}
Can anybody give me some good adivce? Thank you.