www.webdeveloper.com
Results 1 to 4 of 4

Thread: Fixed position relative to parent container

  1. #1
    Join Date
    Sep 2011
    Posts
    31

    Fixed position relative to parent container

    I did a lot of research on this but apparently it's not possible with pure html/css as position:fixed only fixes it to browser window, so I thought I'd ask in this section.
    I have a page container, and inside it are two sections. The left section is a vertical nav bar with some links, while the right section is the actual page content. I want the right side to be scrollable, but the left side to be fixed to the page container (ie won't scroll when I scroll that page), but be able to move when I scroll the entire browser window.

    Code:
    <div id="pagecontainer">
    
        <div id="linkspage">
    
            <div class="sidelinks"> <!--UNSCROLLABLE-->
                <a href="#page1" class="link">Link 1</a>
                <p>
                <a href="#page2" class="link">Link 2</a>
                <p>
                <a href="#page3" class="link">Link 3</a>
                <p>
                <a href="#page4" class="link">Link 4</a>
                <p>
            </div>
    
            <div class="linkscontent"> <!--SCROLLABLE-->
                content of links page
            </div>
    
        </div>
    
        //OTHER PAGES
    
    </div>
    I've already tried to set #pagecontainer and #linkspage to position:relative, and .sidelinks to position:absolute, that doesn't do anything as far as I can tell... or it just doesn't do what I want.

    Here's a picture:

    fixed.png

    Thanks.

  2. #2
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    google clearfix
    Create, Share, and Debug HTML pages and snippets with a cool new web app I helped create: pagedemos.com

  3. #3
    Join Date
    Mar 2009
    Posts
    590
    Assuming you have used CSS to arrange both divs to be side by side in the parent container, you might try something like:

    Code:
    window.onload = function(){
       var side, content;
        side = document.getElementById('sidelinks');
        content = document.getElementById('linkscontent'); //to be scrolled
        content.style.display = "none";  //remove for measurement
        content.style.height = side.offsetHeight + 'px';
        content.style.overflow = "scroll";
        content.style.display = "block"; //make visible again
    }

  4. #4
    Join Date
    Dec 2012
    Location
    NSW Australia
    Posts
    73
    Maybe this will be an answer to your request.

    I would like to remind you that this can be achieved without JavaScript and it is always better to do things with css first.

    HTML Code:
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="utf-8">
    <title>odd ball</title>
    <style>
    .page{background-color:lime;margin:1em;padding:1em;position:relative;max-width:52em;}.stuf1{position:relative;background-color:red;height:30em}.link1{position:absolute;width:10em;top:1px;left:1px;background-color:#CCC}.tent1{position:absolute;width:40em;height:30em;top:1px;left:11em;background-color:pink;overflow:scroll}.stuf2{position:relative;background-color:blue;height:30em}.link2{position:absolute;width:10em;top:1px;left:1px;background-color:#eee}.tent2{position:absolute;width:40em;height:30em;top:1px;left:11em;background-color:purple;overflow:scroll}.stuf3{position:relative;background-color:green;height:30em}.link3{position:absolute;width:10em;top:1px;left:1px;background-color:#999}.tent3{position:absolute;width:40em;height:30em;top:1px;left:11em;background-color:yellow;overflow:scroll}
    </style>
    </head>
    <body>
    <div class="page">
        <div class="stuf1">
    	    <div class="link1">
    		    <ul>
    			    <li>link one</li>
    				<li>link two</li>
    				<li>link three</li>
    				<li>link four</li>
    				<li>link five</li>
    			</ul>
    		</div>
    		<div class="tent1">
    		    <p>content of links page</p><p>content of links page</p><p>content of links page 1</p>
    		    <p>content of links page</p><p>content of links page</p><p>content of links page 2</p>
    		    <p>content of links page</p><p>content of links page</p><p>content of links page 3</p>
    		    <p>content of links page</p><p>content of links page</p><p>content of links page 4</p>
    		    <p>content of links page</p><p>content of links page</p><p>content of links page 5</p>
    		    <p>content of links page</p><p>content of links page</p><p>content of links page 6</p>
    		    <p>content of links page</p><p>content of links page</p><p>content of links page 7</p>
    		    <p>content of links page</p><p>content of links page</p><p>content of links page 8</p>
    		    <p>content of links page</p><p>content of links page</p><p>content of links page 9</p>
    		    <p>content of links page</p><p>content of links page</p><p>content of links page 10</p>
    		    <p>content of links page</p><p>content of links page</p><p>content of links page 11</p>
    		</div>
    	</div>
    	<hr />
    	<div class="stuf2">
    	    <div class="link2">
    		    <ul>
    			    <li>link one</li>
    				<li>link two</li>
    				<li>link three</li>
    				<li>link four</li>
    				<li>link five</li>
    			</ul>
    		</div>
    		<div class="tent2">
    		    <p>content of links page</p><p>content of links page</p><p>content of links page 1</p>
    		    <p>content of links page</p><p>content of links page</p><p>content of links page 2</p>
    		    <p>content of links page</p><p>content of links page</p><p>content of links page 3</p>
    		    <p>content of links page</p><p>content of links page</p><p>content of links page 4</p>
    		    <p>content of links page</p><p>content of links page</p><p>content of links page 5</p>
    		    <p>content of links page</p><p>content of links page</p><p>content of links page 6</p>
    		    <p>content of links page</p><p>content of links page</p><p>content of links page 7</p>
    		    <p>content of links page</p><p>content of links page</p><p>content of links page 8</p>
    		    <p>content of links page</p><p>content of links page</p><p>content of links page 9</p>
    		    <p>content of links page</p><p>content of links page</p><p>content of links page 10</p>
    		    <p>content of links page</p><p>content of links page</p><p>content of links page 11</p>
    		</div>
    	</div>
    	<hr />
    	<div class="stuf3">
    	    <div class="link3">
    		    <ul>
    			    <li>link one</li>
    				<li>link two</li>
    				<li>link three</li>
    				<li>link four</li>
    				<li>link five</li>
    			</ul>
    		</div>
    		<div class="tent3">
    		    <p>content of links page</p><p>content of links page</p><p>content of links page 1</p>
    		    <p>content of links page</p><p>content of links page</p><p>content of links page 2</p>
    		    <p>content of links page</p><p>content of links page</p><p>content of links page 3</p>
    		    <p>content of links page</p><p>content of links page</p><p>content of links page 4</p>
    		    <p>content of links page</p><p>content of links page</p><p>content of links page 5</p>
    		    <p>content of links page</p><p>content of links page</p><p>content of links page 6</p>
    		    <p>content of links page</p><p>content of links page</p><p>content of links page 7</p>
    		    <p>content of links page</p><p>content of links page</p><p>content of links page 8</p>
    		    <p>content of links page</p><p>content of links page</p><p>content of links page 9</p>
    		    <p>content of links page</p><p>content of links page</p><p>content of links page 10</p>
    		    <p>content of links page</p><p>content of links page</p><p>content of links page 11</p>
    		</div>
    	</div>
    </div>
    </body>
    </html>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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

"

"

X vBulletin 4.2.2 Debug Information

  • Page Generation 0.15993 seconds
  • Memory Usage 2,928KB
  • Queries Executed 16 (?)
More Information
Template Usage (34):
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (2)bbcode_code
  • (1)bbcode_html
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (4)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (4)postbit
  • (4)postbit_onlinestatus
  • (4)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (72):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • fetch_postattach_query
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates