Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS grid renders behind parent's scroll bar in Firefox and Safari

Tags:

css

css-grid

I have an absolutely positioned panel (fixed height, overflow scroll) and a grid with square tiles (10 columns). In Chrome, the grid renders correctly:

enter image description here

But in FF/Safari, the last column is displayed behind wrapper's scrollbar which is odd:

enter image description here

enter image description here

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>
like image 891
oleq Avatar asked Nov 26 '19 16:11

oleq


People also ask

Is CSS grid supported in Safari?

The supporting browsers Other than in Internet Explorer, CSS Grid Layout is unprefixed in Safari, Chrome, Opera, Firefox and Edge.

Does CSS grid work on all browsers?

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.

How do I change the scrollbar style in CSS Firefox?

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 a scrollbar with CSS?

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. ...

How do I customize the scrollbar of a WebKit browser?

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.

What is the default value for Firefox's scrollbar style?

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.

How do I change the color of the scrollbar in Firefox?

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.


1 Answers

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/

like image 124
Comandeer Avatar answered Oct 17 '22 16:10

Comandeer