Fixed Header & Scrollable Body Layout Without Scripts

Posted by
Anastasia in HTML & CSS tips on 9/24/20132 min read

Many online documentation formats are related to HTML in one way or another. At that, many online documentation topics are using the same visual layout - a header container with information and quick links; and the topic body in a scrollable container. Looks simple and typical. But have you ever tried to implement this layout without scripting?

This type of layout can be seen in many CHM help systems, exported HTML help systems, and in online help systems. So, this seems to be a standard approach to a help topic layout. It makes sense - you keep important information in the header, so it's always availble for the readers while they scroll through the body. Many technical writers put the following elements to the header: topic title, software product name and version, author name, latest review date, etc. We are also using this layout type in ClickHelp topics, by default (though you can change it):

ClickHelp Topic Example With the Fixed Header Layout Click the image to enlarge.

In many cases, after attempts to implement this layout without scripting, ang getting all sorts of issues in different web browsers, web developers give up and use scripts. In a script, you calculate the position and sizes of elements to make sure your header is right on top when the topic body is being scrolled. This solution is quite good, and it may be the only one in certain situations. However, we want to share another solution that does not use scripting. It uses CSS capabilities to get the same result. Hopefully, it will be useful. Here is the sample code - just put it to an .html file, save, and open in any web browser.

<!DOCTYPE html>
width: 600px;
height: 400px;
position: relative;

height: 50px;
background: #CCEBCC;
width: 100%;

font-size: x-large;
padding: 5px;
border: 1px solid #008f42;

position: absolute;
top: 62px; /* 2 pixels are added by header borders, 10 more by header paddings */
bottom: 0;
background: #EAEAEA;
overflow: auto;
width: 100%;
text-align: justify;

padding-left: 5px;
padding-right: 5px;
border: 1px solid #CDCDCD;
border-top: 0;

<div class="container">
<div class="header">
I am the Fixed Header
<div class="content">
This is the body content - put any amount of text here, it will scroll.

You may wonder why would somebody struggle to get a script-free version when they can use scripting, and when Internet is full of script-based solutions. The answer is two-fold: first, there may be users that have scripts disabled in their web browser; and second, web crawlers take page snapshots with scripts disabled. Keep this in mind for better user experience in your online content.

If you liked the article, follow ClickHelpNews on Twitter to be notified about new articles in this blog, technical communication news, and other related topics.

Happy Technical Writing!
ClickHelp Team


Give it a Try!

Sign up for a 14-day free trial!
Start Free Trial
Post Categories
Want to become a better professional?
Get monthly digest on technical writing, UX and web design, overviews of useful free resources and much more.

Mind if we email you once a month?

Professionals never stop learning. Join thousands of experts subscribed to our blog to get tips, ideas and stories from us once per month.
Learn more on ClickHelp
By using this site, you agree to our Privacy Policy and Terms of Use.

Learn more