CSS Only Horizontal Page Scroll
While I’m not overly worried about the particular site I’m working on being javascript dependant, it’s good to go the progressive enhancement route whenever possible. I thought I’d quickly check to see if there were any glaring issues with a css only version of a horizontal layout. Here’s a quick test page that I threw together.
The markup is literally just a containing div, with a header div and an unordered list to contain the content items (in this case images).
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Horizontal Layout</title>
<link rel="stylesheet" href="css/style.css" type="text/css" />
</head>
<div id="container">
<div id="header">
<h1>Horizontal Layout</h1>
</div><!--end header-->
<ul id="content">
<li><img src="images/image_01.jpg"></li>
<li><img src="images/image_02.jpg"></li>
<li><img src="images/image_03.jpg"></li>
<li><img src="images/image_04.jpg"></li>
<li><img src="images/image_05.jpg"></li>
<li><img src="images/image_06.jpg"></li>
</ul>
</div><!--end container-->
<body>
</body>
</html>
The only important things to note in the stylesheet is that we need to:
1) Give the containing div a width
2) Fix the position of the header div so that it doesn’t go out of view when we scroll
3) Float the list items left
#container {
width:6000px; height:550px;
}
#header {
width:800px; height:150px;
position:fixed;
}
#content {
clear:both;
padding:150px 0px 0px 0px;
}
#content li {
float:left;
}
As straight forward as this method was it forced me to specify a width for the content. Ideally I’d like that width to be dynamic as I’m not sure how many images the client will add. Setting the width to 100% only seems to set the width to 100% of the browser window.
I’ll have a think…
20 Notes