0

I am new to salesforce development. I want to display an image in LWC in salesforce. I added the image in static resource and add the line in lightning component

<img src="{Resource.Img1}" />

The image is showing in the LWC but when I add width and height to the image it disappears. How can I add width and height and how I can add css in LWC.

3
  • Hi. Can you share how are you adding the width and height to the image (the exact code that you are using)? Commented Oct 24, 2021 at 20:26
  • I got this. I added a inline style to the img tag and it worked. But I am unable to add <style type="text/css"> in my lightning component. Commented Oct 24, 2021 at 21:25
  • <style> tag is not the way to include styles in a LWC. If you want to include your own styles in a LWC, in your component folder create a .css next to the .js and the .html and put your own styling there. Then, you can reference it in your .html. Commented Oct 25, 2021 at 19:33

1 Answer 1

0

You can add inline css as below and update the height and width of your image according to your requirement.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.