Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Salesforce
  3. Question
Salesforce

How to make inner divs scrollable in a lightning component?

Asked by Makram Ben Aug 22, 2021 6.0K views 2 answers
Share

About this question

I am developing a lightning component to drag and drop some items. It is called from a quick action on a record detail page. What I have noticed is that if the divs inside of it are too large, the entire component will start scrolling. What I want is that the left-hand side and the right-hand sides scroll separately.

Screenshot:

enter image description here

When it's viewed on a large enough screen(or with low amount of items) it is fine. However, when the screen size changes:

enter image description here

I am not able to drag the "Fwd: Shizzle" onto "Other" anymore.

Code:

    
<!-- Left hand side -->
<input type="checkbox" name="accordion-role" id="{!obj.Id + '_rad'}">


<!-- Right hand side -->
<input type="checkbox" name="accordion-role" id="{!obj.fileName + '_rad'}" disabled="{!obj.fileId == null || obj.fileId == ''}">


Your answer

2 Answers

Ranjana Admin JanBask Expert Latest answer

Answered on May 10, 2024

To make inner divs scrollable within a Lightning Component, you can use CSS to define the desired scrolling behavior. Here's a basic example of how you can achieve this:



And in your CSS file:

.THIS .outer-container {
    /* Set the height and width of the outer container */
    height: 300px; /* Adjust as needed */
    width: 100%; /* Adjust as needed */
    overflow: auto; /* Enable scrolling */
}
.THIS .inner-container {
    /* Set the height and width of the inner container */
    height: 500px; /* Adjust as needed */
    width: 100%; /* Adjust as needed */
    /* Other styles for inner content */
}

In this example:

  • The outer container (div.outer-container) defines the dimensions of the visible area. It has a fixed height, and if the content inside it exceeds this height, it will become scrollable vertically.
  • The inner container (div.inner-container) contains the content you want to display. It should have dimensions larger than the outer container if you want scrolling to occur.
  • By setting overflow: auto; on the outer container, you enable scrolling when the content exceeds the container's dimensions.

Adjust the height, width, and other styles according to your requirements.

Remember to replace .THIS with the appropriate namespace if you're using Salesforce Lightning Components. Also, consider responsive design and usability aspects when defining dimensions and scrolling behavior.

Was this helpful?

More Salesforce discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Salesforce Blogs

Guides, tips and career advice on Salesforce from JanBask experts.