2

I'm unable to stretch a <lightning-button> to occupy the full width of its container. While applying a style of display: block or a class of slds-size_12-of-12, for example, those styles/classes are applied to the <lightning-button> tag... however... when rendered, the tag appears to wrap an inner <button> tag, and the styles are not transferred to that tag, and it's that inner tag that appears to have all the content.

EDIT: The above completely rewritten for clarity

<lightning-layout>
    <lightning-layout-item flexibility="grow">
        <lightning-button
            label="click me"
            onclick={action}
            class="slds-size_12-of-12">
        </lightning-button>
    </lightning-layout-item>

    <lightning-layout-item flexibility="no-flex">
        ...

enter image description here

enter image description here

6
  • can you provide code of it ? Commented Feb 8, 2019 at 6:07
  • @OleksandrBerehovskyi I added an additional screenshot and explanation
    – David
    Commented Feb 8, 2019 at 6:23
  • with screenshot you force those who want to help you to manually type code from screenshot. Can you please paste text code instead of image ? Commented Feb 8, 2019 at 6:25
  • @OleksandrBerehovskyi You're right. That was dumb. Tired. Code attached. I'll pick this up in the morning. Thanks for your help.
    – David
    Commented Feb 8, 2019 at 6:48
  • 1
    @MarkPond I just discovered the class.. it's new this release.. HOWEVER!.. it doesn't work when applied to the LWC lightning-button tag. I've worked around it by just using a standard button tag and adding the missing SLDS classes. Still... it should work on the LWC tag... but it doesn't.
    – David
    Commented Feb 9, 2019 at 0:27

2 Answers 2

5

Many here suggested to use <button> instead of <lightning-button> as the slds-button_stretch class won't apply to it. But here is what you can do to use the <lightning-button> provided by salesforce lwc and at the same time stretch it to 100% width.

I insisted to use <lightning-button> instead of <button> because it's too easy while you want to use a button with an icon in <lightning-button> than using a normal <button>

Here's what I did to get a button with icon and full width:

<lightning-button icon-name="utility:upload" onclick={yourfunction} variant="brand" label="Download" style="display: grid; width: 100%"></lightning-button>

Hope this helps you. Thanks!

0
2

You can use the stretch attribute of the lightning-button to achieve that:

enter image description here

For example:

<div>
    <lightning-button
        variant="brand"
        label="Get Started"
        title="Get Started"
        stretch
    ></lightning-button>
</div>
1
  • This, right here, should be the accepted answer Commented Jul 9 at 19:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .