1

So basically I have this div with height:400px and inside of it I have a div with dynamic height, what I want to do is if the div inside the main div exceeds 400px in height then it should have a scrollbar so I can scroll to the bottom of it. Can I do this in css or I need javascript ?

1
  • Does inside div: height:400px;overflow:auto; work? Commented Dec 17, 2013 at 7:52

4 Answers 4

1

You need to use

overflow-y:auto

with your parent div container.

Js Fiddle Demo

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

Comments

0

try this line:

overflow-x:hidden;

Comments

0

The only good reason to do this is if you cannot modify the div with overflow:hidden and need a background color/border that resizes with content.

HTML

<div class="d1">

    <div class="d2">
          <div class="d3"> D3 will resize with content</div>
    </div>
</div>

CSS

.d1{height:400px; overflow:hidden}
.d2{height:400px; overflow:auto; }
.d3{background-color:#F00;}

Comments

0

Simply use this:

#container
{
    height: 400px;
    overflow-y: scroll;
}
.dynamic-height
{
    height: auto;
}

jsfiddle

Comments

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.