24

To reproduce, please select the "All" tab first and type keywords to filter out badges until there're less than three badges.

Two badges:

enter image description here

One badge:

enter image description here

No badge:

enter image description here

6
  • 5
    Related report on MSE: Track/Select your next badge modal displays badges with incorrect width and positioning Commented Jul 19, 2021 at 12:30
  • 5
    Thankfully it's less broken than it was before. Commented Jul 19, 2021 at 14:30
  • 2
    I can recreate the issue if I search for arc. However, if I search for are, the result is also two badges--but they display properly. Commented Jul 20, 2021 at 0:33
  • 3
    @DaveL17 Perhaps it's because you've got the Enthusiast badge, switch to the All tab and search again, and there'll be three badges. Commented Jul 20, 2021 at 0:50
  • 2
    @WenfangDu confirmed. Interestingly, if I leave the filter set to all and search for vis, I get two badges and they're displayed properly (one of the resulting badges is an earned badge). Commented Jul 20, 2021 at 0:56
  • 2
    @DaveL17 I haven't earned any of these two badges, but if I repeat your steps, they're displayed normally as well. Commented Jul 20, 2021 at 1:00

1 Answer 1

23

Short answer

A fixed max-height rule is at the heart of the issue. In the 6 to 8 weeks it takes to fix this, you can use the following overrides (apologies for using !important, but since SE's rulesets also use it, there is no other way):

.popup._badge-selection {
  /* prevents vertical centering of the container */
  justify-content: start !important;
}

.popup._badge-selection .-list-item {
  /* removes content overflow */
  max-height: unset !important;
}

.popup .js-badge-list-container {
  /* keeps badge horizontal alignment */
  justify-content: center;
  /* removes badge vertical stretch */
  height: unset !important;
}

If anyone needs a quick JavaScript snippet, here it is:

((_w, d) => {
  const style = d.createElement("style");
  d.head.append(style);
  const { sheet } = style;
  if (!sheet) return;
  [
    `.popup._badge-selection {
            justify-content: start !important;
        }`,
    `.popup._badge-selection .-list-item {
            max-height: unset !important;
            min-width: 256px;
        }`,
    `.popup .js-badge-list-container {
            justify-content: center;
            height: unset !important;
        }`,
  ].forEach(rule => sheet.insertRule(rule));
})(window, document);

Long answer

As the badge container can grow indefinitely, at some point the wrapped description text (which also has padding-top and padding-bottom of 16px and 12px respectively) starts to overflow the container. Here is an extract from the ruleset:

.popup._badge-selection .-list-item {
  /* ...other rules */
  max-height: 128px;
}

Simply removing the rule would've solved the problem if not for the inline height: 75% set on the parent container, which makes an unrestrained badge container stretch the full height of the parent leading to:

marshal badge container stretching the height

One could add the ai-start class to prevent the flex item from stretching, but this obviously messes up the tile layout of multiple badges:

messed up tile layout

Another difficulty is presented by the fact badge filtering also uses inline styles (display: none <-> display: block) to show/hide badges depending on the query and not the Stacks classes (d-none and d-block respectively).

Given the above, the most reasonable thing to do is to unset the height override, but this presents another challenge since the #popup-next-badge container has a flex__center helper class which centers flex items on both main and cross axis resulting in:

centered flex items

Fortunately, this is solved with the help of justify-content rule set to start (with !important as Stacks helper class also uses the rule) on the .popup._badge-selection container. Note that the inner js-badge-list-container needs another override back to center if you want the badges to be horizontally centered.

If you feel that it gets a bit too spacey when there are only one or two badges, a min-width rule on ._list-item class set to 256px or higher will help. In the end, you should get a result similar to this (for the ruleset summary see the short answer):

fixed badge height and width
6
  • 5
    You might want to post this on the related MSE post as well. I don't believe cross-posting answers on multiple Metas is an issue, though I'm not entirely sure about that. Commented Jul 19, 2021 at 21:31
  • 2
    @cigien if no one finds out that I am actually wrong about this, I'll likely make a post on MSE too, yeah, good idea. I still have to minify and uglify the snippet + can expand on a couple of points, so I don't think cross-posting will be an issue :) Commented Jul 19, 2021 at 21:43
  • 2
    I kinda had to double take on which site we're in when reading this answer. Commented Jul 20, 2021 at 2:37
  • 1
    I have nightmares of the W3C introducing a !veryimportant just for people trying to deal with this site. Commented Sep 21, 2021 at 14:33
  • 1
    @TylerH I propose we use !important! and adding a ! for each additional level of importance :) Commented Sep 21, 2021 at 14:46
  • @OlegValter Brilliant! Commented Sep 21, 2021 at 14:47

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.