I have an absolutely positioned panel (fixed height, overflow scroll
) and a grid with square tiles (10 columns). In Chrome, the grid renders correctly:
But in FF/Safari, the last column is displayed behind wrapper's scrollbar which is odd:
What I want is the same behavior in all browsers (like in Chrome). How do I get this?
jsFiddle
:root {
--ck-character-grid-tile-size: 24px;
}
body * {
box-sizing: border-box;
}
.wrapper {
height: 100px;
overflow-y: auto;
overflow-x: hidden;
background: red;
position: absolute;
top: 50px;
left: 50px;
outline: 1px solid black;
}
.grid {
display: grid;
grid-template-columns: repeat(10, 1fr);
background: blue;
}
button {
background: yellow;
width: var(--ck-character-grid-tile-size);
height: var(--ck-character-grid-tile-size);
min-width: var(--ck-character-grid-tile-size);
min-height: var(--ck-character-grid-tile-size);
border: 0;
padding: 0;
overflow: hidden;
outline: 1px solid black;
}
<div class="wrapper">
<div class="grid">
<button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button><button>x</button>
</div>
</div>
The supporting browsers Other than in Internet Explorer, CSS Grid Layout is unprefixed in Safari, Chrome, Opera, Firefox and Edge.
Most developers are afraid to start using CSS Grid because of browser support, but CSS grid is fully supported in all main browsers: Chrome, Firefox, Safari, Edge including their mobile versions.
As of Firefox 99.0 all macOS scrollbar modes (configured under System Preferences > Show Scroll Bars) can be colored. You can set scrollbar-width to one of the following values (descriptions from MDN): auto The default scrollbar width for the platform.
How To Style Scrollbars with CSS 1 Prerequisites. Familiarity with the concepts of vendor prefixes, pseudo-elements, and graceful degradation. 2 Styling Scrollbars in Chrome, Edge, and Safari. ... 3 Styling Scrollbars in Firefox. ... 4 Building Future-Proof Scrollbar Styles. ... 5 Conclusion. ...
For webkit browsers, you can use the following pseudo elements to customize the browser's scrollbar: ::-webkit-scrollbar the scrollbar. ::-webkit-scrollbar-button the buttons on the scrollbar (arrows pointing upwards and downwards). ::-webkit-scrollbar-thumb the draggable scrolling handle.
The default value for Firefox's scrollbar style is 0, which sets it to match your platform. You can restore the original default setting by clicking Edit and entering 0 in the value box for the widget.non-native-theme.scrollbar.style option.
Custom Scrollbars is a Firefox and Google Chrome extension with which you can change the scrollbar's color scheme, width, roundness, and buttons. The MUO guide linked below provides details for how to utilize that extension. The widget.non-native-theme.scrollbar.style flag is a great, albeit hidden, Firefox customization setting.
According to CSS Tricks article, Preventing a Grid Blowout, the issue is connected with the sizing of the grid:
The real fix isn't all that difficult — we only need to understand what is happening. I can't promise I'm explaining this 100% accurately, but the way I understand it, the minimum width of a grid column is auto. […]
To apply our fix, we need to make sure that there is the column has a definite minimum width instead of auto.
The fix proposed in article, minmax
, seems to be working also for the case in question:
grid-template-columns: repeat( 10, minmax( 0, var(--ck-character-grid-tile-size) ) );
The simpler version, using fr
unit, also seems to work:
grid-template-columns: repeat( 10, minmax( 0, 1fr ) );
Demo of the fix: https://jsfiddle.net/gp8r0f94/
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