I am trying with the following style:
.scrollDiv { height:auto; max-height:100%; overflow:auto; }
My Requirement is:
max-height
of div is equal to screen heightUsing width, max-width and margin: auto; Then, you can set the margins to auto, to horizontally center the element within its container. The element will take up the specified width, and the remaining space will be split equally between the two margins: This <div> element has a width of 500px, and margin set to auto.
Make the div a "cover", and make the image position: absolute . Then position it. Also, if you're making a gallery, then make the image's max-height: 90% or something like that. You can set the image height of height: 90vh , so it still has a 10% view height marginal room for spacing.
The max-height property in CSS is used to set the maximum height of a specified element. Authors may use any of the length values as long as they are a positive value. max-height overrides height, but min-height always overrides max-height .
Use CSS Viewport units for this.
Example:
.scrollDiv { max-height: 100vh; overflow: auto; }
More info: https://www.w3schools.com/cssref/css_units.asp
You can use $(window).height()
to set the max-height to screen height:
$('.scrollDiv').css('max-height', $(window).height());
UPDATE
As mentioned in the John's answer. With the latest CSS3 API you can use vh
's(View port unit for height)
.scrollDiv { max-height: 100vh; overflow: auto; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With