lrtad
lrtad

Reputation: 257

how to add scroll to div that have no fixed height

I have a div which I don't want to give fixed height.

I want this div to have a scroll in case the content is larger then the window,

I add this to my div:

overflow: auto;
overflow-x: hidden;

but I still don't see the scroll if the content is bigger the the window.

Any thought on the same is appreciated.

Upvotes: 0

Views: 2991

Answers (3)

Arun Bertil
Arun Bertil

Reputation: 4648

Try

max-height:400px;//some px value
overflow:auto;

Upvotes: 0

Falguni Panchal
Falguni Panchal

Reputation: 8981

try this

max-height:set from javascript and overflow-x:scroll;

For Example

http://jsfiddle.net/PJbhH/

Upvotes: 0

lexmihaylov
lexmihaylov

Reputation: 737

You could use javascript to determine the height of the window and after that set the max-height css property like @Fags suggested.

<script>
$(function() {
  var $window = $(window);
  var setMaxHeight = function() {
    $('#div_id').css('max-height', $window.height());
  }
  $window.on('resize', setMaxHeight);
  setMaxHeight();
});
</script>

Upvotes: 1

Related Questions