In visualforce page, apex:stylesheet tag is used to refer a css file from static resource. In lightning app it could be ltng:require tag. Let see an example about the usage of ltng:require tag.
Example:
Adding CSS File into Static Resource:
Copy the below CSS code and save this code with extension of CSS in your local, then Go to salesforce Setup --> Static Resource --> New --> Enter a name as "CSSTableLibrary" --> upload the css file which is saved before --> Cache Control is Public --> Save.
Referring CSS from Static Resource:
Example:
Adding CSS File into Static Resource:
Copy the below CSS code and save this code with extension of CSS in your local, then Go to salesforce Setup --> Static Resource --> New --> Enter a name as "CSSTableLibrary" --> upload the css file which is saved before --> Cache Control is Public --> Save.
- .tableEnhancer {
- margin:0px;padding:0px;
- width:100%;
- box-shadow: 10px 10px 5px #888888;
- border:1px solid #000000;
- -moz-border-radius-bottomleft:8px;
- -webkit-border-bottom-left-radius:8px;
- border-bottom-left-radius:8px;
- -moz-border-radius-bottomright:8px;
- -webkit-border-bottom-right-radius:8px;
- border-bottom-right-radius:8px;
- -moz-border-radius-topright:8px;
- -webkit-border-top-right-radius:8px;
- border-top-right-radius:8px;
- -moz-border-radius-topleft:8px;
- -webkit-border-top-left-radius:8px;
- border-top-left-radius:8px;
- }.tableEnhancer table{
- border-collapse: collapse;
- border-spacing: 0;
- width:100%;
- height:100%;
- margin:0px;padding:0px;
- }.tableEnhancer tr:last-child td:last-child {
- -moz-border-radius-bottomright:8px;
- -webkit-border-bottom-right-radius:8px;
- border-bottom-right-radius:8px;
- }
- .tableEnhancer table tr:first-child td:first-child {
- -moz-border-radius-topleft:8px;
- -webkit-border-top-left-radius:8px;
- border-top-left-radius:8px;
- }
- .tableEnhancer table tr:first-child td:last-child {
- -moz-border-radius-topright:8px;
- -webkit-border-top-right-radius:8px;
- border-top-right-radius:8px;
- }.tableEnhancer tr:last-child td:first-child{
- -moz-border-radius-bottomleft:8px;
- -webkit-border-bottom-left-radius:8px;
- border-bottom-left-radius:8px;
- }.tableEnhancer tr:hover td{
- }
- .tableEnhancer tr:nth-child(odd){ background-color:#30d1d1; }
- .tableEnhancer tr:nth-child(even) { background-color:#ffffff; }.tableEnhancer td{
- vertical-align:middle;
- border:1px solid #000000;
- border-width:0px 1px 1px 0px;
- text-align:left;
- padding:6px;
- font-size:14px;
- font-family:Arial;
- font-weight:normal;
- color:#000000;
- }.tableEnhancer tr:last-child td{
- border-width:0px 1px 0px 0px;
- }.tableEnhancer tr td:last-child{
- border-width:0px 0px 1px 0px;
- }.tableEnhancer tr:last-child td:last-child{
- border-width:0px 0px 0px 0px;
- }
- .tableEnhancer tr:first-child td{
- background:-o-linear-gradient(bottom, #28b8ed 5%, #28b8ed 100%); background:-webkit-gradient( linear, left top, leftbottom, color-stop(0.05, #28b8ed), color-stop(1, #28b8ed) );
- background:-moz-linear-gradient( center top, #28b8ed 5%, #28b8ed 100% );
- filter:progid:DXImageTransform.Microsoft.gradient(startColorstr="#28b8ed", endColorstr="#28b8ed"); background: -o-linear-gradient(top,#28b8ed,28b8ed);
- background-color:#28b8ed;
- border:0px solid #000000;
- text-align:center;
- border-width:0px 0px 1px 1px;
- font-size:16px;
- font-family:Comic Sans MS;
- font-weight:bold;
- color:#ffffff;
- }
- .tableEnhancer tr:first-child:hover td{
- background:-o-linear-gradient(bottom, #28b8ed 5%, #28b8ed 100%); background:-webkit-gradient( linear, left top, left bottom,color-stop(0.05, #28b8ed), color-stop(1, #28b8ed) );
- background:-moz-linear-gradient( center top, #28b8ed 5%, #28b8ed 100% );
- filter:progid:DXImageTransform.Microsoft.gradient(startColorstr="#28b8ed", endColorstr="#28b8ed"); background: -o-linear-gradient(top,#28b8ed,28b8ed);
- background-color:#28b8ed;
- }
- .tableEnhancer tr:first-child td:first-child{
- border-width:0px 0px 1px 0px;
- }
- .tableEnhancer tr:first-child td:last-child{
- border-width:0px 0px 1px 1px;
- }
Creating Lightning Component:
Paste the below code in your lighting component.
Paste the below code in your lighting component.
- <aura:component >
- <ltng:require styles="/resource/CSSTableLibrary"/>
- <div class="tableEnhancer">
- <table>
- <tr>
- <td>
- Title 1
- </td>
- <td >
- Title 2
- </td>
- <td>
- Title 3
- </td>
- </tr>
- <tr>
- <td >
- Row 1
- </td>
- <td>
- Row 1
- </td>
- <td>
- Row 1
- </td>
- </tr>
- <tr>
- <td >
- Row 2
- </td>
- <td>
- Row 2
- </td>
- <td>
- Row 2
- </td>
- </tr>
- <tr>
- <td >
- Row 2
- </td>
- <td>
- Row 2
- </td>
- <td>
- Row 2
- </td>
- </tr>
- <tr>
- <td >
- Row 3
- </td>
- <td>
- Row 3
- </td>
- <td>
- Row 3
- </td>
- </tr>
- </table>
- </div>
- </aura:component>
Referring CSS from Static Resource:
Above lightning component code is referring a static resource file using ltng:require tag with the attribute of styles.
<ltng:require styles="/resource/CSSTableLibrary"/>
Where CSSTableLibrary is the "Static Resource" name.
<div class="tableEnhancer"> --> tableEnhancer is the CSS class name. It's referring from static resource.
Referring CSS from Static Resource ZIP file(From folder):
<ltng:require styles="/resource/CSSTableLibrary/css/TableEnhancer.css"/>
CSSTableLibrary - Static Resource name.
css - Folder name
TableEnhancer.css - CSS file name.
No comments:
Post a Comment