Dynamically resizing navigation div to main content

后端 未结 2 1946
暖寄归人
暖寄归人 2021-01-16 04:45

Greetings and Hello
I am trying to put together a wordpress site, now because the content in the main div is going to be a different height with every page I need the na

相关标签:
2条回答
  • 2021-01-16 05:25

    the new code if anyone needs it

    function adjust()
    {
        if (document.getElementById('content').offsetHeight < document.getElementById('sidebar').offsetHeight)
            {
            hgt1=document.getElementById('sidebar').offsetHeight;
            document.getElementById('content').style.height=hgt1+'px';
            }
            else
            {
            hgt2=document.getElementById('content').offsetHeight;
            document.getElementById('sidebar').style.height=hgt2+'px';
            }
    
    }
    window.onload=adjust;
    window.onresize=adjust;
    
    0 讨论(0)
  • 2021-01-16 05:30

    could be several reasons:

    1) as Waleed says you are missing a closure.

    2) If you did not set an explicit style for

    document.getElementById('sidebar').style.height
    

    it will return ""

    3) Be careful assuming style.height and offsetHeight are equivalent. Depending on browsers, one or the other may be accounting for margins and paddingC:

    0 讨论(0)
提交回复
热议问题