1FpGLLjZSZMx6k
1FpGLLjZSZMx6k

Reputation: 1067

Display: grid breaks inner element's width

I have a dropdown list and two buttons inside a material card. When I click on the dropdown quickly after reloading the page (say within the first 2 seconds), the width of the buttons sometimes collapse. The effect does not occur when I stay on the page a while (say 10 seconds) and then click on the dropdown.

I noticed that the effect does not occur when I remove the outer display: grid. Why does this effect occur? What can I do to get rid of it? I need the grid for other stuff I intentionally left out in the Stackblitz (Full)

Stackblitz (Edit)

Error:

Error

Upvotes: 0

Views: 152

Answers (1)

Daniel Guzman
Daniel Guzman

Reputation: 676

It seems like the issues is with the align-items: baseline; If it's not completly required, you may change it to center or start.

Also, I suggest you the repeat function for grid column:

.grid {
    width: 100%;
    display: grid;
    column-gap: 24px;
    align-items: center; // baseline -> center

    &.second {
        row-gap: 24px;
        grid-template-columns: repeat(6, 1fr);
    }
}

or just override it for .second, in case this causes any issue with other elements:

&.second {
    align-items: center;
    row-gap: 24px;
    grid-template-columns: repeat(6, 1fr);
}

Upvotes: 1

Related Questions