1

I have a flex-container with a fractional pixel width with 8 flex-children. I expect the container to not overflow, but it does.

  • The browser is Chrome or Edge on Windows. (Not in Firefox.)
  • The container has width of xxx.45px.
  • There are exactly 8 children; they have flex: 1. (1-7 children works as expected.)
  • It only occurs on my secondary screen with screen scaling 100%, not on the primary with 125%.

The code:

.d1 {
  display: flex;
  overflow: auto;
  height: 100px;
  width: 100.45px;
}

.d1 > * {
  flex: 1;
  border: 1px solid blue;
}
<div class="d1">
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
</div>

On Chrome and Edge I see a horizontal scollbar that I don't see on Firefox. The calculated widths are not what I expect either; the parent is 240.438px wide (I expected 240.45px) and each child is 30.063px wide (meaning the sum is 240.504px).

6
  • 3
    The container has width of xxx.45px. --> not really, you will have rounding calculation which leads to the issue you are having Commented Apr 23 at 12:38
  • 1
    A pixel on a monitor is a physical unit - how do you intend on splitting a pixel exactly 0.45? Commented Apr 23 at 12:40
  • 1
    I expect the browser to not display the horizontal scrollbar. For 240.4px there's no scollbar. I'm sure the browser does some rounding (converting to display pixels for example), but that implementation detail shouldn't affect this. Unless it's a bug; then I might report it. Btw, 1px is a "CSS pixel". A physical pixel is called "device pixel". Commented Apr 23 at 12:58
  • 1
    I could remove overflow: auto but that would cause actual legitimate overflow to be inaccessible. I want to know why the overflow occur and how to avoid it in the first place. Commented Apr 24 at 7:02
  • 1
    This is a bug in blink. crbug.com/40804774 I don't know if there is a surefire way to avoid it other than using integer main sizes, and that might not even be foolproof. Commented Apr 24 at 17:12

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.