Easy Scrollable Area Code
By Stephen Bucaro
Everything wants to be on the front page of your Web site. Not just on the front page, but
"above the fold" on the front page (the area visible when the page first loads without
scrolling). How can you fit more content into a limited area? One way is to place the content
in boxes where the user needs to scroll to read the entire article.
In this article you'll learn how to create a scrollable area. Then you'll learn how to use
style code to customize the appearance of your scrollable area. Next you'll learn how to
layout your webpage with scrollable areas. And last, you'll learn how to load your scrollable
area's from external files so you never need to edit your front page again.
The most basic scrollable area is an html textarea control. The code for a textarea is shown below.
<textarea cols=40 rows=12 readonly>
Place your text here
</textarea>
Use the cols and rows attributes to set the size of your scrollable area. Use
the readonly attribute to prevent the user from entering text into the textarea. You can
use any number of textareas on your webpage and they will automatically flow into position on
the webpage. You can use Style code to customize the appearance of your textareas.
The disadvantage of using a textarea is that technically a textarea is a child element of
a form. If you have not defined a form on your webpage, the textareas will belong to
document.forms(0). If you have defined a form, or forms on your webpage, the textareas will
belong to document.forms(?). A testarea could inadvertently become an element of a submitable
form. Then, when the user submits the form, the text in your text area will be sent back to the
server along with the contents of the other form elements.
Another disadvantage of using a textarea is that it can contain only test. If you use an
html div (division) element, it can contain html code. You can actually create an
entire webpage within a div.
The code for a div scrollable area is shown below.
<style type="text/css">
.scrollArea
{
width: 300px;
height: 250px;
padding: 10px;
border-style: solid;
border-width: 1;
overflow: auto;
}
</style>
<span class="scrollArea">
Place your text here
</span>
|