Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Apr 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Adjust DIV when scrollbar appears

    I have 3 DIVs in my HTML page. I have a header, content area and a footer. The CSS for the header is the following:
    Code:
    #header
    {
    	position:absolute; 
    	top:0; 
    	left:0; 
    	width:100%; 
    	height:120px; 
    	overflow:auto;
    	background:#FFFFFF;
    }
    The CSS for the container div is:
    Code:
    #container
    {
    	position:fixed; 
    	top:121px;
    	left:0;
    	bottom:30px; 
    	right:0; 
    	overflow:auto; 
    	background:#FFFFFF;
    	padding:0px;
    	text-align:center;
    }
    And the CSS for the footer is:
    Code:
    #footer
    {
    	position:absolute; 
    	bottom:0; 
    	left:0;
    	width:100%; 
    	height:30px; 
    	overflow:auto; 
    	text-align:right; 
    }
    When I resize the browser window to make it smaller, eventually horizontal scrollbars appear in the header DIV (the container and footer DIVs will eventually contain horizontal scrollbars if I continue to make the window smaller). The header DIV will also contains very small vertical scrollbars which are barely usable. When the horizontal scrollbars appear in the header, how can I adjust the DIVs so that the header div does not need the vertical scrollbar? It seems that if the header div is given more height and container div is shifted down,there would be no need for the vertical scrollbar. Is there a way of having the browser do this automatically or do I have to detect when the horizontal scrollbar appears and adjust each div accordingly? Thanks.

  • #2
    Senior Coder
    Join Date
    Aug 2010
    Location
    High Point, NC
    Posts
    3,332
    Thanks
    5
    Thanked 363 Times in 360 Posts
    Its your use of positioning, which is not needed at all here. I assume it's a single column layout, since you only mention a header, footer, and container, so have a look at this I worked up quickly. I added a page wrapper in order to center your page in the browser.

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Untitled Document</title>
    <style type="text/css">
    #wrapper {
    	width: 960px;
    	margin: 0 auto;
    }
    #container {
    	background-color: #CCC;
    }
    #header {
    	background-color: #666;
    }
    #footer {
    	background-color: #666;
    }
    </style>
    </head>
    
    <body>
    <div id="wrapper">
      <div id="header">Content for  id "header" Goes Here</div>
      <div id="container">Content for  id "container" Goes Here Content for  id "container" Goes Here Content for  id "container" Goes Here Content for  id "container" Goes Here Content for  id "container" Goes Here Content for  id "container" Goes Here Content for  id "container" Goes Here Content for  id "container" Goes Here Content for  id "container" Goes Here Content for  id "container" Goes Here Content for  id "container" Goes Here Content for  id "container" Goes Here Content for  id "container" Goes Here Content for  id "container" Goes Here Content for  id "container" Goes Here Content for  id "container" Goes Here Content for  id "container" Goes Here Content for  id "container" Goes Here Content for  id "container" Goes Here Content for  id "container" Goes Here Content for  id "container" Goes Here Content for  id "container" Goes Here Content for  id "container" Goes Here Content for  id "container" Goes Here Content for  id "container" Goes Here Content for  id "container" Goes Here Content for  id "container" Goes Here Content for  id "container" Goes Here Content for  id "container" Goes Here Content for  id "container" Goes Here Content for  id "container" Goes Here Content for  id "container" Goes Here Content for  id "container" Goes Here Content for  id "container" Goes Here Content for  id "container" Goes Here Content for  id "container" Goes Here</div>
      <div id="footer">Content for  id "footer" Goes Here</div>
    </div>
    </body>
    </html>
    Teed

  • #3
    New to the CF scene
    Join Date
    Apr 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    My container div contains content that should be scrollable vertically. While the user scrolls through the content, I want the header and footer to remain in place. When the user makes the browser window smaller, I want horizontal scrollbars to appear in the header because there are links in the header that the user may need to click on. If those link are no longer on the page because of the resizing of the browser, then scrollbars are the only way to get to those links.

    In your example, the content area does not scroll independently of the header and footer.

    I attached a couple of screenshots that may help to better visualize what I am trying to do. In the 2nd screenshot I would like for the header div to automatically increase its width so that a vertical scrollbar does not appear. I am fine with the horizontal scrollbar appearing in the header div. At the same time, I would like the container div to adjust its top style attribute so that it does not cut off the header div when it increases its height.

    The 1st screen shot is how it appears when all the divs are able to be contained by the browser window horizontally.





  •  

    Posting Permissions

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