-
-
Notifications
You must be signed in to change notification settings - Fork 78.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
For web-compat, please avoid using negative margins instead of defining a proper width. #35277
Comments
Is this only a Firefox issue? If so, why does this affect Firefox only? Very hesitant to make a change here that could affect how customizable and approachable our grid system is today. I'm also thinking about how we're likely to shift to something with |
@mdo many browsers base on Chromium |
@mdo , using negative margins in this way is relying on an acknowledged bug in Chromium, as linked. In fact a Chrome dev suggested that I file this issue, so it doesn't strike me as something I would want to rely on, especially if an interoperable drop-in replacement seems to exist. Is there a reason why the width method strikes you as any less customizable or approachable as negative margins? To me it speaks at least as clearly of your intent, while not risking running into other unexpected quirks with negative margins. Edit: as WinterSilence mentioned, Edge and Opera and Brave and many other browsers use Chromium under-the-hood, so it shouldn't be a surprise as to why they would "work", since they would share the same Chromium bug. |
I understand many browsers are based on Chromium—the question was in regards to the issue as reported specifically mentions Firefox and no other browser. I'm very hesitant to change something here without fully understanding what's happening given this technique has been in use for the nearly 10 years we've been working on Bootstrap. That's not a reason to keep it, but it's also a reason to not walk away from it outright. Looking at the page at https://curriculum.gov.bc.ca/curriculum/arts-education/10/media-arts, I'm super confused by the HTML in here. Feels rather convoluted and there's too much |
That's exactly the reason why relying on negative margins is a risk, especially for a framework used by many sites. They have subtle, not-well-defined behaviour, and won't always behave as you might expect, especially with floats and such. In this site's case, it's Firefox that's bitten, but Webkit is also very different from Chromium these days and doesn't share all of the same layout quirks and bugs anymore. If you want to better understand the underlying reason, the Chromium team has some notes in the crbug. But from what I can tell, Safari and Chrome still have enough code in common that they share this bug, while Firefox does not. So that's why only Firefox seems affected, whereas all three seem to work fine with the width example. Not that I mean to call you out on this or anything; I'll understand if you don't feel it's even worth trying this. But it's just a race to the bottom in that case. How likely are individual sites to fix this, if bootstrap isn't? We'll ultimately all just end up stuck with the buggy and subtle behaviour as Chrome won't be able to fix it, Firefox will have to burn time adopting Chromium bugs instead of working on other things web devs want, etc. I'd rather try to avoid that if possible. |
Using the test created by @dholbert From left to right:
If you do not want to modify the negative margin, maybe you could instead add the rule
|
And yet another site breaking because of this. |
Unfortunately most of the options don’t exactly do what the current Bootstrap grid behavior does. Check this Codepen where I’ve shown the current sizing, with the |
@mdo thanks for circling back to this! If it helps, I'm seeing the same rendering and responsive wrapping behavior on all of the lines, in Chrome, Firefox and Safari on my Macbook. But I'm not 100% certain of what your expected behavior here is meant to be, so if there are other cases/tests for which you'd like the rendering to match across browsers, would you mind sharing them all (assuming that's practical)? That would help us narrow down any interop issues and hopefully find variants which pass all the cases that are deemed important. |
Forgive me for being slow on the uptake here, but it looks to me as though the browsers are all just doing what you're asking them to for flexboxes that are assigned different widths; Row 1: 100% width, so no empty space, the cols are distributed with default of even width. What were the results you were hoping for? Was it perhaps for the empty space to be distributed equally, such that the items are "centered" and have equal empty space to their left and right? If so, you likely want to add |
Back at laptop and have desktop screenshots, from Safari and Firefox. Here's the breakdown on what works and what doesn't:
Without any other viable options, I'm likely going to close this issue as I feel I've spent too much time on it already knowing none of the suggestions will work. I'm also just realizing I never saw a specific reduced test case for this issue when building with Bootstrap. All that means is there's less information for me to act on and inform my research on potential fixes. |
@mdo, then could you please help to me understand what purpose the negative margins are meant to serve? Is it just to force the rows back into the padding of the container? If so, wouldn't it be viable to reduce the padding on the container instead? (they both seem to use the same variable in your demo). |
https://getbootstrap.com/docs/5.1/layout/grid/#how-it-works outlines that nicely already, and the grid examples show how content is meant to align thanks to the combination of:
All that together gets you Bootstrap's grid system in a nutshell. Closing this as a won't fix for now as I see no immediate path forward without significant complication or regression. Open to further testing and ideas on how to solve for this though, as well as clearer demonstrations (live, reduced test cases) of how Bootstrap may be causing this in some browsers. ❤️ |
Prerequisites
Describe the issue
As was discovered at https://webcompat.com/issues/90988 (and others), there is a web-compatibility issue with bootstrap where it is relying on quirky Chromium behaviour. In short, relying on negative margins on items to force them to wrap, in this kind of pattern:
In this kind of case, using
width
is more interoperable and reliable:The code relying on negative margins appears to be here, according to @bfgeek on the webcompat issue. Would it be possible to alter it to use calc as above?
Reduced test cases
n/a
What operating system(s) are you seeing the problem on?
Windows, macOS, Android, iOS, Linux
What browser(s) are you seeing the problem on?
Firefox
What version of Bootstrap are you using?
5.1.1
The text was updated successfully, but these errors were encountered: