Results 1 to 2 of 2

Thread: Scroll Bar in Fixed Height Div

  1. #1
    Join Date
    Oct 2009
    Posts
    20

    Scroll Bar in Fixed Height Div

    Is it possible to have a div that is.. say 500px and then have content in the div that is much longer than that, but to simply have a scroll bar appear in the div so that it remains at 500px?

    Thanks for any help!

    Alex

  2. #2
    Join Date
    Sep 2008
    Posts
    899
    Code:
    <head>
    <style type="text/css" media="screen">
       #div1 {width:300px;height:500px;overflow:auto;}
         p {width:260px;}
    </style>
    </head>
    <body>
    <div id="div1"><p>
    Your content that is more than 500px in height goes here,
    but it is kept at well less than 300px in width by the paragraph style 
    (so you have a vertical scroll bar but do not a horizontal scroll bar).
    You can actually put another div in this one and give it a width that
    is well less than 300px. That way you can put text, images, and
    other objects in the "inner" div and keep from having a
    horizontal scroll bar without using a p tag or having to
    otherwise make sure that your content does not exceed
    a total of 300px minus your padding, borders, margins,
    and the width of the hoizontal scroll bar.
    </p></div>
    </body>
    </html>
    And if you don't want to do the math and just want to set your inner div to 300px, you can put this in your stylesheet or <style> in the head:
    Code:
    #div1 {width:300px;height:500px;overflow-x:hidden;overflow-y:auto;}
    It may not work in older IE though. I can't remember.
    Last edited by djlebarron; 18 Feb 2010 at 03:17 PM.

Similar Threads

  1. iframe doesnt scroll with parent div IE7
    By xnewbie in forum Web Design, HTML Reference and CSS
    Replies: 0
    Last Post: 09 Feb 2010, 09:45 AM
  2. DIV Scroll Bar locked with an image...
    By vn1985 in forum Web Design, HTML Reference and CSS
    Replies: 1
    Last Post: 04 Jan 2010, 09:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •