question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Don't require CSS height or max-height

See original GitHub issue

Currently mCustomScrollbar() requires the container div to have “height” or “max-height” CSS attribute. That’s is not very cool in cases in which we don’t want to set such attributes (i.e. when using the new W3C FlexBox model with “flex-direction: column” in which the divs can fill the entire vertical space of the main box).

Why is “height” or “max-height” CSS attribute required? why not get the height via jQuery height() method?

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:19 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
ERobishawcommented, Jun 6, 2016

I’m having good success with 3.1.3 using flexbox with all browsers except Safari. With Safari, my container is set to:

flex: 1 1 100%;
max-width: 100%;
max-height: 100%;
box-sizing: border-box;
min-height:100%;

Which results in the .mCustomScrollBox height at 0 in Safari.

The style for this container is setting style=“max-height:280px” (for example) as calculated. This works for everyone but safari. For safari, it needs either min-height or height also set to this value (height:280px) for it to render correctly.

Here’s the fix:

                        /* css flexbox fix, detect/set max-height */
                        mCustomScrollBox.css("max-height","none");
                        if (mCustomScrollBox.height() !== $this.height()) {
                            mCustomScrollBox.css("max-height",$this.height());
                            **mCustomScrollBox.css("height",$this.height());**
                        }

1reaction
malihucommented, Jun 11, 2013

I cannot see any scrollbar on the example.

In order to make the yellow box have a scrollbar you must set a max-height value on it and since you have fixed height values, you can set its max-height:125px;. In your example, you’ve set height values for everything but the yellow box, so you don’t need jQuery to set its height. 200px minus 25px minus 50px equals 125px. You can apply that in your css. You could also do this with percentages.

A scrollbar cannot work without a height/max-height (like in your example, where no scrollbar is present). This applies on any kind of scrollbar (browser, javascript, whatever…).

If there’s no height, how can an engine know when to stop expanding an overflow:auto element and apply a scrollbar?

Additionaly, The custom scrollbar plugin has the set_height option parameter, where you can set its value to pixels or percentage. For example:

$('.contentContainer').mCustomScrollbar({
    set_height: "80%"
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

max-height - CSS: Cascading Style Sheets - MDN Web Docs
The max-height CSS property sets the maximum height of an element. It prevents the used value of the height property from becoming larger ......
Read more >
Child with max-height: 100% overflows parent - css
When you specify a percentage for max-height on a child, it is a percentage of the parent's actual height, not the parent's max-height...
Read more >
max-height | CSS-Tricks
The max-height property in CSS is used to set the maximum height of a specified element. Authors may use any of the length...
Read more >
Min and Max Width/Height in CSS - Ahmad Shadeed
In this article, we will go through the maximum and minimum CSS properties for width and height, and to explain each one in...
Read more >
CSS Properties – Max-width, Min-width, Max-height, and Min ...
The Max-Height Property ... The max-height property operates similarly to the max-width property, but it affects the height instead of the width.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found