Lightning Web Components CSS – Adjust Width of Lightning-Button in LWC

Given the following:

<div style="display:inline-block">
    <lightning-button style="..." class="..." onclick={...} label="..."></lightning-button>
</div>

How can I adjust the width of the Lighting-Button?

I essentially want all my buttons to be the same width for UX purposes.

I have already tried the suggestions in various other posts (using CSS) with no luck.

Best Answer

You can't. The button inside is designed to only be as large as it needs to be. I took a look at the code, and it renders like this:

<lightning-button c-app_app="" class="button-classes">
    <button type="button" class="slds-button slds-button_neutral">
        Demo
    </button>
</lightning-button>

Where button-classes is whatever you put in to the class attribute:

<lightning-button class="button-classes" label="Demo"></lightning-button>

Therefore, it seems reasonable that nothing you do will work, short of writing your own custom component. As frustrating as that is, that's the current state of affairs until the component or the related CSS is fixed.

Related Topic