Can't get height of div to adjust

user3685679

I'm in a pickle.

I'm working on a layout, and I need the main div to adjust to the window size, mainly to get that middle div to make a scrollbar upon resizing. It's acting as a table cell currently, which is why it's forcing itself to simply become taller instead of using a scrollbar. It's in a containing div in the efforts to keep from doing this though.

<div id="ALL">
    <div id="VOLTRON">
        <div id="MAINSIDEBAR">ok</div>
        <div id="CONTENT">
            <div id="TICKER">please</div>
            <div class="WRAP">
                <div id="POSTSGOHERE">
                    <p>Lorem ipsum dolor sit amet, ...</p>
                </div>

                <div id="RIGHTSIDEBAR">WELL THEN.</div>
            </div>
        </div>

    </div>
</div>

I resorted to Jquery, and though I found a code for this very thing, it's not working.

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type='text/javascript'>
$(function(){
    $('#ALL') .css({'height': (($(window).height()))+'px'});
    $(window).resize(function(){
        $('#ALL') .css({'height': (($(window).height()))+'px'});
    });
});
</script>

I've tried setting a max height, I've tried setting it to vh instead of percent, I've tried containing it, and I feel like I've exhausted a pretty decent amount of time on this conundrum myself to finally get help.

Here is the entire code, in case that also helps. I'm certain that the way I'm doing this is the reason it's not working.

So, any idea for a fix for this? And why what I'm trying isn't working?

EDIT: I need to specify this again: I want the entire "table" to only fit the window, but the purple div is the one that should scroll. The problem is, though I've set it to overflow-y: scroll; it just changes the size of the entire container. The entire table just grows past the window to compensate for the overflow.

benomatis

Your code looks good, you just don't see it as it takes the exact size of the window. You would see it better if you subtracted a little off of it and added the overflow-y:scroll to #ALL instead of the container:

#ALL {
    background-color: red;
    max-width: 100%;
    max-height: 100%;
    overflow-y: scroll;
}
$(function () {
    $('#ALL').css('height', $(window).height()-50 + 'px');
    $(window).resize(function () {
        $('#ALL').css('height', $(window).height()-50 + 'px');
    });
});

HERE IS A DEMO

EDITED: Following your edit, and I know this would threw off your layout completely, but the only thing that worked for me, if you wanted the purple one to move only, was to remove the table-cell display and set the height to the container instead of ALL, and adding the scroll only to that:

#ALL {
    background-color: red;
    max-width: 100%;
    max-height: 100%;
}
#POSTSGOHERE {
    background-color: purple;
    max-height: inherit;
    overflow-y: scroll;
}
$(function () {
    $('#POSTSGOHERE').css('height', $(window).height()-50 + 'px');
    $(window).resize(function () {
        $('#POSTSGOHERE').css('height', $(window).height()-50 + 'px');
    });
});

I updated the demo

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Can't adjust height in image

From Dev

Can't get the height of a div element

From Dev

Can't get DIV's equal in height

From Dev

Image won't correctly adjust to the height of a div

From Dev

Can't Adjust Height by % On Any DIVs

From Dev

Auto adjust Height of the div

From Dev

left div doesn't adjust to right divs height

From Dev

how can i get the sidebar height to adjust to the main content boxes?

From Dev

How to dynamically adjust DIV height?

From Dev

Adjust div height based on scroll

From Dev

CSS: Parent div with overlapping child div - can't get parent height right

From Dev

Check if div has style height. If yes, don't adjust height

From Dev

HTML Can't Change Height of Div

From Dev

Height can't be defined for a div with display table

From Dev

Can't position div 50% height css

From Dev

Why can't I adjust my div's position

From Dev

How can i auto adjust the height of my div based on image Size

From Dev

Adjust div height dynamically based on scroll

From Dev

How to adjust div on depending on screen height

From Dev

Detect height change and adjust position of a div?

From Dev

Adjust child div height to be the same as parent/sibling

From Dev

Dynamically adjust height of div with transition over image

From Dev

How to adjust div on depending on screen height

From Dev

Can't get img width and height jQuery

From Dev

Can't get height and width of image in javascript

From Dev

Can't get img width and height jQuery

From Dev

Can't get WKWebView content height correctly

From Dev

Can't get canvas element height to equal container height

From Dev

Why I can't left div height to be same right div

Related Related

HotTag

Archive