2

What I am trying to do is align divs in another div from the bottom.. The code I have right now is :

#container{
height: 375px;
display: table-cell;
width: 660px;
vertical-align: bottom;
margin:none;
overflow-y:auto;    
}

#container > div{
margin:none;
width:660px;
}

This seemed to work. But when the content inside the container div increased the height of container also increased though I have set a fixed height and overflow-y to auto. What should I do to make it work?

JsFiddle: http://jsfiddle.net/qNw7E/1/

4
  • 1
    post the code to a JSFIDDLE... Commented Nov 22, 2013 at 12:05
  • Not sure if it will work, but have you tried restricting the row height, instead of just the cell? Commented Nov 22, 2013 at 12:05
  • You want the inner div to expand until it is equal to the height of the parent (375px) and then you want a scroll bar to appear on the parent? Commented Nov 22, 2013 at 12:09
  • use max-height instead of height Commented Nov 22, 2013 at 12:24

3 Answers 3

1

I have used absolute positioning to try to fix your problem - fiddle here. Even when more lines of content are added, the height of the container will stay the same and a scrollbar will appear instead.

The CSS is simple:

#container {
    width: 660px;
    height: 375px;
    position: relative;
    background: #eee;
    overflow: hidden;
}

#container .content {
    width: 100%;
    max-height: 100%;
    position: absolute;
    bottom: 0;
    left: 0;
    overflow: scroll;
}

The main container has a set height and hides any overflow. The content div inside is absolutely positioned to the bottom of this div and can never exceed the height of the main container. If it reaches 100% of the main container's height then a scrollbar will appear.

Try adding more content in and you'll see the scrollbar appear.

Sign up to request clarification or add additional context in comments.

3 Comments

doesn't work.. Please check the jsfiddle link i have added in the question
You haven't added in the div with class content inside the main container like I suggested. Please see my fiddle here and look at the HTML and CSS.
Thanks Adam McElroy. After I have added another div inside the container div and put my contents in that div, it's working. Thanks
1

Your issue is that that the CSS spec is quite clear that overflow does not apply to table cells, browsers will ignore it. You may have better luck using inline-block for your aligned elements and set vertical-align:bottom on the parent. You might also be able to use a nested div in each TD but that's still tricky because 100% height doesn't work in children of table-cells either.

When you think about it, it actually makes sense. Table cells are supposed to scale to fit their children, not the other way around.

1 Comment

doesn't work.. Please check the jsfiddle link i have added in the question
0

working demo or jsFiddle here ( note: i update some your html format ).

html

<div style="margin-bottom:50px;">
    <div id="container">
        <div class="hack-overflow">
            <div class="data">you data here</div>
        </div>
    </div>
</div>


<div>
    <div id="container">
        <div class="hack-overflow">
            <div class="data">you data here</div>
            <div class="data">you data here</div>
            <div class="data">you data here</div>
            <div class="data">you data here</div>
            <div class="data">you data here</div>
            <div class="data">you data here</div>
            <div class="data">you data here</div>
            <div class="data">you data here</div>
            <div class="data">you data here</div>
        </div>
    </div>
</div>

css

#container{
    height: 375px;
    display: table-cell;
    width: 660px;
    vertical-align: bottom;
    margin:0 0 30px 0;
    background-color:#9C0;  
}

#container .hack-overflow{
    width:100%;
    height:auto;
    overflow:hidden;
    overflow-y:auto; 
    max-height:375px
}

#container .data{
    margin:0;
    width:660px;
    height:50px; 
    background-color:#F90; 
    border:#333 1px solid;
}

1 Comment

This is not what I want.. Please check the Jsfiddle link I added in the question

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.