Hey guys, today in this post we are going to learn about How to create Responsive Layouts page Header, Footer, Left Sidebar, Right Sidebar & Main Body Container uses of lightning:layout & lightning:layoutItem Elements in Salesforce LWC.
A lightning-layout is a flexible grid system for arranging containers within a page or inside another container. The default layout is mobile-first and can be easily configured to work on different devices.
Create the content of the layout by including lightning-layout-item components within lightning-layout. You can place HTML tags and text between the lightning-layout-item components, but you can’t place other components or expressions between them. To know more details about lightning-layout, Click Here
Files we used to create lightning-layout page in LWC
lwcPageLayout.html | LWc HTML File | Template HTML file to create lightning layout page in lwc |
lwcPageLayout.js | LWC JavaScript File | It’s hold a javascript Import and export function in lwc. |
lwcPageLayout.js-meta.xml | XML Meta File | It is used to where this lightning web component file you want to display as like lightning__AppPage, lightning__RecordPage, lightning__HomePage. |
lwcPageLayout.css | Custom Style CSS | It is used to fixed alignment of lightning layout page in lwc |
lwcPageLayoutApp.app | Lightning Application | It is used for call the component to preview on browser. |
Final Output
You can download file directly from github by Click Here.
Other related post that would you like to learn in Salesforce
- Find the below steps
Create Lightning Web Component HTML
Step 1:- Create Lightning Web Component HTML β‘ lwcPageLayout.html
SFDX:Lightning Web Component β‘ New β‘ lwcPageLayout.html
lwcPageLayout.html [Lightning Web Component HTML]
<template>
<div class="slds slds-p-around--large">
<div><a href="https://www.w3web.net/" target="_blank" rel="noopener noreferrer"><img src="https://www.salesforce.com/content/dam/sfdc-docs/www/logos/logo-salesforce.svg" width="auto" height="auto"/></a></div>
<div class="c-container">
<lightning-layout multiple-rows="true">
<lightning-layout-item padding="around-small" size="12">
<div class="page-section page-header">
<h2><strong style="color: #ff8000;">Header Section</strong></h2>
</div>
</lightning-layout-item>
<lightning-layout-item padding="around-small" size="12">
<lightning-layout>
<lightning-layout-item padding="around-small" size="3">
<div class="page-section page-right">
<h2><strong style="color: #ff8000;">Left Sidebar</strong></h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation
ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit
in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
</div>
</lightning-layout-item>
<lightning-layout-item padding="around-small" size="6">
<div class="page-section page-main">
<h2><strong style="color: #ff8000;">Main Container</strong></h2>
<p>Donec viverra pellentesque aliquet. Praesent quis tristique mauris, ac tincidunt ante.
Nulla lectus nisi, tempor quis malesuada ac, consequat in velit. Nullam aliquam mauris eu magna
dictum, in ornare risus convallis. Nunc condimentum ornare libero sit amet rhoncus. Aliquam tellus nisl,
tristique sit amet congue in, tristique vel risus. Morbi leo ligula, blandit nec commodo at, pulvinar
vitae libero. Mauris ipsum erat, aliquam a turpis vitae, faucibus viverra arcu. Donec id purus
luctus enim elementum molestie sit amet ac libero.
</p>
<p>Mauris cursus felis elementum ipsum placerat, in maximus justo pretium. Nam nec sapien
maximus justo feugiat tristique. Mauris viverra erat vitae arcu feugiat, sed posuere purus vulputate.
Sed et nulla ut magna iaculis fringilla. Integer eget blandit elit. Phasellus nulla augue, lobortis a
elementum tempus, auctor et felis. Fusce quis lorem tincidunt risus ullamcorper pharetra. Sed elit
nulla, efficitur a lorem quis, mollis tristique elit. Etiam odio libero, ornare sed vehicula
in, sagittis et erat. Integer at justo molestie, suscipit dui vel, scelerisque ex. Nulla non metus
pulvinar, egestas neque et, tincidunt tellus. Praesent egestas scelerisque tristique. Nullam
sodales ex acmetus tincidunt accumsan. Cras vitae consequat odio. Pellentesque facilisis lobortis
lorem, at placerat mauris sagittis a.
</p>
</div>
</lightning-layout-item>
<lightning-layout-item padding="around-small" size="3">
<div class="page-section page-right">
<h2><strong style="color: #ff8000;">Right Sidebar</strong></h2>
<div class="slds-nav-vertical__section">
<ul>
<li class="slds-nav-vertical__item"><a class="slds-nav-vertical__action" href="https://www.w3web.net/" target="_blank" rel="noopener noreferrer">w3web Tutorial</a></li>
<li class="slds-nav-vertical__item"><a class="slds-nav-vertical__action" href="https://www.w3web.net/tutorial/salesforce-integration/" target="_blank" rel="noopener noreferrer">Salesforce Integration</a></li>
<li class="slds-nav-vertical__item"><a class="slds-nav-vertical__action" href="https://www.w3web.net/tutorial/salesforce-lwc/" target="_blank" rel="noopener noreferrer">Salesforce LWC</a></li>
<li class="slds-nav-vertical__item"><a class="slds-nav-vertical__action" href="https://www.w3web.net/tutorial/lightning-component/" target="_blank" rel="noopener noreferrer">Salesforce Aura Component</a></li>
<li class="slds-nav-vertical__item"><a class="slds-nav-vertical__action" href="https://www.w3web.net/tutorial/trigger/" target="_blank" rel="noopener noreferrer">Apex Trigger</a></li>
<li class="slds-nav-vertical__item"><a class="slds-nav-vertical__action" href="https://www.w3web.net/tutorial/visualforce/" target="_blank" rel="noopener noreferrer">Visualforce</a></li>
<li class="slds-nav-vertical__item"><a class="slds-nav-vertical__action" href="https://www.w3web.net/tutorial/jquery/" target="_blank" rel="noopener noreferrer">JQuery/Javascript</a></li>
<li class="slds-nav-vertical__item"><a class="slds-nav-vertical__action" href="https://www.w3web.net/all-published-post/" target="_blank" rel="noopener noreferrer">Sitemap W3web</a></li>
<li class="slds-nav-vertical__item"><a class="slds-nav-vertical__action" href="https://www.w3web.net/about-us/" target="_blank" rel="noopener noreferrer">About Us</a></li>
<li class="slds-nav-vertical__item"><a class="slds-nav-vertical__action" href="https://www.w3web.net/contact-us/" target="_blank" rel="noopener noreferrer">Contact Us</a></li>
</ul>
</div>
</div>
</lightning-layout-item>
</lightning-layout>
</lightning-layout-item>
<lightning-layout-item flexibility="auto" padding="around-small" size="12">
<div class="page-footer page-section">
<h2><strong style="color: #ff8000;">Footer</strong></h2>
</div>
</lightning-layout-item>
</lightning-layout>
</div>
<br/><br/>
<!--Start RelatedTopics Section-->
<div style="border:1px #ddd solid; padding:10px; background:#eee; margin:40px 0;">
<p data-aura-rendered-by="435:0"><img src="https://www.w3web.net/wp-content/uploads/2021/05/thumbsUpLike.png" width="25" height="25" style="vertical-align:top; margin-right:10px;" data-aura-rendered-by="436:0"><strong data-aura-rendered-by="437:0"><span style="font-size:16px; font-style:italic; display:inline-block; margin-right:5px;">Don't forget to check out:-</span><a href="https://www.w3web.net/" target="_blank" rel="noopener noreferrer" style="text-decoration:none;" data-aura-rendered-by="440:0">An easy way to learn step-by-step online free Salesforce tutorial, To know more Click <span style="color:#ff8000; font-size:18px;" data-aura-rendered-by="442:0">Here..</span></a></strong></p>
<br/><br/>
<p data-aura-rendered-by="435:0"><img src="https://www.w3web.net/wp-content/uploads/2021/07/tickMarkIcon.png" width="25" height="25" style="vertical-align:top; margin-right:10px;" data-aura-rendered-by="436:0"><strong data-aura-rendered-by="437:0"><span style="font-size:17px; font-style:italic; display:inline-block; margin-right:5px; color:rgb(255 128 0);">You May Also Like β</span> </strong></p>
<div style="display:block; overflow:hidden;">
<div style="width: 50%; float:left; display:inline-block">
<ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;">
<li><a href="https://www.w3web.net/lwc-get-set-lightning-checkbox-value/" target="_blank" rel="noopener noreferrer">How to get selected checkbox value in lwc</a></li>
<li><a href="https://www.w3web.net/display-account-related-contacts-in-lwc/" target="_blank" rel="noopener noreferrer">how to display account related contacts based on AccountId in lwc</a></li>
<li><a href="https://www.w3web.net/create-lightning-datatable-row-actions-in-lwc/" target="_blank" rel="noopener noreferrer">how to create lightning datatable row actions in lwc</a></li>
<li><a href="https://www.w3web.net/if-and-else-condition-in-lwc/" target="_blank" rel="noopener noreferrer">how to use if and else condition in lwc</a></li>
<li><a href="https://www.w3web.net/get-selected-radio-button-value-and-checked-default-in-lwc/" target="_blank" rel="noopener noreferrer">how to display selected radio button value in lwc</a></li>
</ul>
</div>
<div style="width: 50%; float:left; display:inline-block">
<ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;">
<li><a href="https://www.w3web.net/display-account-related-contacts-lwc/" target="_blank" rel="noopener noreferrer">display account related contacts based on account name in lwc</a></li>
<li><a href="https://www.w3web.net/create-lightning-datatable-row-actions-in-lwc/" target="_blank" rel="noopener noreferrer">how to insert a record of account Using apex class in LWC</a></li>
<li><a href="https://www.w3web.net/fetch-picklist-values-dynamic-in-lwc/" target="_blank" rel="noopener noreferrer">how to get picklist values dynamically in lwc</a></li>
<li><a href="https://www.w3web.net/edit-save-and-remove-rows-dynamically-in-lightning-component/" target="_blank" rel="noopener noreferrer">how to edit/save row dynamically in lightning component</a></li>
<li><a href="https://www.w3web.net/update-parent-object-from-child/" target="_blank" rel="noopener noreferrer">update parent field from child using apex trigger</a></li>
</ul>
</div>
<div style="clear:both;"></div>
<br/>
<div class="youtubeIcon">
<a href="https://www.youtube.com/channel/UCW62gTen2zniILj9xE6LmOg" target="_blank" rel="noopener noreferrer"><img src="https://www.w3web.net/wp-content/uploads/2021/11/youtubeIcon.png" width="25" height="25" style="vertical-align:top; margin-right:10px;"/> <strong>TechW3web:-</strong> To know more, Use this <span style="color: #ff8000; font-weight: bold;">Link</span> </a>
</div>
</div>
</div>
<!--End RelatedTopics Section-->
</div>
</template>
Create Lightning Web Component Javascript
Step 2:- Create Lightning Web Component Javascript β‘ lwcPageLayout.js
SFDX:Lightning Web Component β‘ New β‘ lwcPageLayout.js
lwcPageLayout.js [LWC JavaScript File]
import { LightningElement } from 'lwc';
export default class LwcPageLayout extends LightningElement {
}
Create Custom Style CSS
Step 3:- Create Custom Style CSS β‘ lwcPageLayout.css
SFDX:Lightning Web Component β‘ New β‘ lwcPageLayout.css
lwcPageLayout.css [LWC Custom Style CSS]
.c-container {
border: 1px solid #d8dde6;
margin: 10px 0 20px 0;
}
.page-section {
border: solid 1px #ccc;
padding: 1rem;
}
.page-header,
.page-footer {
height: 50px;
}
.page-main {
background: #f8f8f8;
}
.page-left,
.page-right {
background: #f0efef;
}
Create Lightning Web Component Meta XML
Step 4:- Create Lightning Web Component Meta XML β‘ lwcPageLayout.js-meta.xml
SFDX:Lightning Web Component β‘ New >> lwcPageLayout.js-meta.xml
lwcPageLayout.js-meta.xml [LWC Meta Data XML]
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>45.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightning__AppPage</target>
<target>lightning__RecordPage</target>
<target>lightning__HomePage</target>
</targets>
</LightningComponentBundle>
Create Lightning Application
Step 5:- Create Lightning Application : lwcPillsApp.app
From Developer Console >> File >> New >> Lightning Application
lwcPageLayoutApp.app [Component Application File]
<aura:application extends="force:slds">
<c:lwcPageLayout/>
</aura:application>
Further post that would you like to learn in Salesforce
What is lightning layout?
A lightning:layout is a flexible grid system for arranging containers within a page or inside another container.
What is the use of lightning layout in Salesforce?
lightning-layout enables you to create several types of columns. Create a simple layout by enclosing single or multiple lightning-layout-item components within lightning-layout .
What can be done using page layout?
Page layouts control the layout and organization of buttons, fields, s-controls, Visualforce, custom links, and related lists on object record pages.
Related Topics | You May Also Like
Our Free Courses β
π Get Free Course β
![]() π Salesforce Administrators π Salesforce Lightning Flow Builder π Salesforce Record Trigger Flow Builder |
π Get Free Course β
![]() π Aura Lightning Framework π Lightning Web Component (LWC) π Rest APIs Integration |