CSS Styling To Your Lightning Component
Now let's create lightning component first and then we'll add style to it.
<aura:component >
<div> Hello HTML</div>
<h2>Check the style in this list</h2>
<ul>
<li >I am red</li>
<li > I am blue</li>
<li > I am green</li>
</ul>
</aura:component>
- Now we'll add styling to it in STYLE section.
.THIS {
background-color:grey;
}
.THIS .red{
background-color:red;
}
.THIS .green{
background-color:green;
}
.THIS .blue{
background-color:blue;
}
- Let's break down above code in 4 different sections to understand it.
.THIS {
background-color:grey;
}
- This above first section will define background colour as grey for all text inside the component.
.THIS .red{
background-color:red;
}
- This above second section will define background colour as red for .red CSS class. Which means whenever we want text background colour as red then we will use this class.
- Similarly for green and blue background colour, whenever we want to use a background colour as green or blue we will just call .green or .blue class inside HTML tag.
- To learn more basics about HTML and CSS on Link.
- Now let's add our CSS to a lightning component which we have created above
<aura:component >
<div > Hello HTML </div>
<h2>Check the style in this list</h2>
<ul>
<li class="red">I am red</li>
<li class="blue"> I am blue</li>
<li class ="green"> I am green</li>
</ul>
</aura:component>
- In this way, we'll add our CSS style class inside HTML tags.
- Now let's see a preview of the above lightning component by adding it inside the lightning application.
APPLICATION HelloStyleApp.app
ALTERNATIVE WAY
- You can also use existing styling from Static Resource. For that, we just have to upload your styling or bootstrap file in Static Resource and refer it inside a lightning component by using the following tag
©Navigation
Setup -> Static Resources -> New (upload your file here)
- To refer uploaded file we will add below code inside a lightning component
<ltng : require style= "/resource/filename"/>
<div class="StyleNameFromFile">
Hello Salesforce Kid
<div/>
- The above code will use class StyleNameFromFile from filename file which provides style to Hello Salesforce Kid.
WOHOOO......YOU HAVE JUST ADDED STYLE IN YOUR LIGHTNING COMPONENT.
Happy learning ☁️⚡️ (Learn. Help. Share.)
HOW TO ADD CSS STYLE TO SALESFORCE LIGHTNING COMPONENT ?
Reviewed by
on
Rating:
Hey your blogs are really helpful. I’m learning through this and it’s very easy to understand. Thanks for sharing such stuff. Please keep posting.
ReplyDeleteBe the precise blog if you have wants to learn about this topic. You comprehend considerably its nearly onerous to argue to you (not that I personally would needHaHa). You undoubtedly put a new spin for a topic thats been discussing for some time. Nice stuff, simply nice! website designer nyc
ReplyDeleteConsiderably, the particular post is truly the greatest with this deserving subject. To be sure together with your results and also can easily thirstily look forward to Your own potential improvements. Simply just declaring thank you will, no doubt not simply just be sufficient, for your wonderful quality within your writing. I will immediately grab your rss to remain up to date with any kind of updates. Real perform as well as much success inside your company dealings! web design in new york
ReplyDeleteYou produced some decent points there. I looked online for your problem and located most people will go together with with the website. branding firms san francisco
ReplyDeleteGlad to be one of many visitants on this awful web site : D. sf design agency
ReplyDeleteCool you write, the information is very good and interesting, I'll give you a link to my site. Sexy Lingerie
ReplyDeleteCool you write, the information is very good and interesting, I'll give you a link to my site. visit this site
ReplyDeletedf
ReplyDeleteIndividuals expect an individual more moderate on the off chance that he is wearing fashionable garments.
ReplyDeletehttps://deets4style.com
I have such countless things on my daily agenda of Do-It-Yourself fashion projects.
ReplyDeleteDeets 4 Style
Beauty is not limited by age; people of all ages can embrace skincare and grooming routines to enhance their natural beauty. Deets4Style
ReplyDelete