limit contents within a div with a scrollbar exclusively for that content

Within my project, I have a total of 5 different div sections: header, left dropdown menu, center content div, right menu guide, and bottom footer. I am looking to ensure that the center content div remains in the middle of the screen while allowing for dynamic content insertion without affecting the overall layout with unnecessary scrollbars. I would like only the content div to be able to contain a scrollbar. Can anyone offer advice or guidance on accomplishing this?

view image here

Answer №1

If you are looking for a fresh and modern take on CSS layouts, then you should definitely check out this code snippet. It utilizes the new CSS grid layout module, which allows you to create layouts that are independent of content and not tied to a specific flow. For more details, refer to the Can I Use Reference

body {
  overflow: hidden;
}

.AppShell {
  display: grid;
  height: 100vh;
  overflow: hidden;
  grid-template-rows: 4fr 20fr 4fr;
  grid-template-columns: 200px 10fr 200px;
  grid-template-areas: "header header header"
                       "leftside content rightside"
                       "footer footer footer";
}

.Header {
  grid-area: header;
  background-color: powderblue;
}

.LeftSide {
  grid-area: leftside;
  background-color: sandybrown;
}

.Content {
  grid-area: content;
  background-color: mediumturquoise;
  overflow: auto;
}

.RightSide {
  grid-area: rightside;
  background-color: papayawhip;
}

.Footer {
  grid-area: footer;
  background-color: tomato;
}
<main class="AppShell">
  <section class="Header">Header</section>
  <section class="LeftSide">Left</section>
  <section class="Content"><div>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tenetur ex excepturi veritatis dicta debitis repellendus illo, laboriosam corporis, nostrum ratione, voluptatem, accusantium est optio laborum soluta totam odit facere architecto.</div>
  <div>Debitis a, adipisci tempore error repudiandae labore assumenda natus modi illo alias impedit esse amet beatae culpa enim tenetur maxime ipsa fuga voluptatem nobis sint nulla optio soluta sit ad.</div>
  <div>Voluptatem officia asperiores dolores magnam perferendis praesentium, id, impedit facilis dignissimos enim, pariatur esse. Nam praesentium quam incidunt perspiciatis, consectetur vel, architecto quia reiciendis nobis vitae eligendi dolorum voluptatibus fugit?</div>
  <div>Alias dolor dicta incidunt laboriosam id accusamus nesciunt doloremque harum reprehenderit, in quo corrupti, obcaecati, aliquid pariatur totam ullam quia ab ratione ex nobis ut! Saepe ab eos deleniti adipisci.</div>
  <div>Quaerat, placeat dolorem rem, incidunt illum harum suscipit illo! Tempore hic deleniti perferendis a numquam recusandae minus quibusdam aperiam harum magnam excepturi reprehenderit, cum, voluptatibus similique, voluptatem sit temporibus accusantium!</div>
  <div>Molestiae consequuntur fugit voluptatum quasi illum quam animi quibusdam minima neque culpa, optio recusandae, ipsa est. Iure sunt, porro sequi. Ipsa dolor, obcaecati laborum nulla vitae? Eligendi, magnam labore vitae.</div>
  <div>Cum natus maiores, impedit ipsum expedita quo accusantium, aliquam nulla, ipsa quia eveniet eos ex. Beatae consectetur maiores cumque sapiente facilis, cum impedit quibusdam dicta consequatur odio, officiis temporibus facere.</div>
  <div>Excepturi ipsa eligendi dicta fuga laudantium dolorum cupiditate iste quo neque non maiores molestiae doloremque dignissimos, iure provident culpa cumque praesentium in assumenda beatae possimus vel. Eum quod, libero expedita?</div>
  <div>Mollitia fuga explicabo natus nobis, laborum itaque hic molestias atque, laboriosam, iste eos nemo vel sed asperiores! Neque dolore quo vel maxime exercitationem quod, sint. Similique delectus quo sit! Temporibus?</div>
  <div>Sunt sequi ducimus obcaecati perspiciatis ipsam, provident expedita qui unde nesciunt, est asperiores odio consequatur incidunt tempora adipisci iusto mollitia enim. Iste quaerat non, obcaecati, ea aliquid quasi quidem. Impedit?</div></section>
  <section class="RightSide">Right</section>
  <section class="Footer">Footer</section>
</main>

Answer №2

To achieve the desired outcome, make sure to include a max-height and overflow: auto in the CSS for the content division located at the center of the page.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The issue with VS Code is that it is running the wrong file instead of

Whenever I try to run my Python file, it keeps opening the previous HTML file instead. Despite clicking "run" on my Python file in VS Code, the terminal is not executing (as it normally does), and instead VS Code continues to open the previously opened HT ...

Leveraging jQuery's .when and .then methods allows for

I'm attempting to utilize a shared ajax function that is meant to retrieve the value returned from the PHP script. function fetchAjax(url, data, type) { result = 0; $.when( $.ajax({ type: "POST", url: url, data: data, ...

Guide to automatically compressing images during the file upload process

Is there a way to automatically compress images larger than 4MB to less than 1MB before uploading them in AngularJS? Any suggestions on how to achieve this? Here is the sample file: JSFIDDLE var myApp = angular.module('myApp', []); myApp.dir ...

The Navbar's expansion is being enhanced by non-collapsible items in the Boostrap 4 dropdown menu

I recently came across a helpful snippet in this question Bootstrap 4 - Navbar items outside the collapse that allowed me to create non-collapsible items for smaller viewports. However, I encountered an issue with a dropdown menu inside one of these items ...

Customizing Background Image in Internet Explorer 10 with JavaScript

Lately, as I work on developing my website, I've added an option for users to change the background image. This feature worked perfectly fine on Windows 7 and XP using Internet Explorer, but recently I upgraded to Windows 8 with IE 10 and now changing ...

Populate a dropdown menu in HTML using a PHP array

I am looking to populate an HTML dropdown using a PHP array. Currently, my code generates an empty dropdown and then displays the array below it on the screen. Below is the HTML snippet. <label for="column1">Variable for Column 1: ...

Choose every fourth row in the table

Is there a way to alternate the background colors of selected groups of 4 rows in a table? I want to make one group red and the next group blue. Any suggestions or ideas on how to achieve this? <table> <tr style="background-color: red;"> ...

Tips for adding a class to an SVG when clicked

I want to make an SVG change color to white when clicked and its container (icon_container) to change to blue. How can I achieve this? Below is the code snippet: state = { active: false, }; click = () => { this.setState({active: !this.state.active ...

Issue "The only acceptable numeric escape in strict mode is '' for styled elements in Material-UI (MUI)"

Attempting to utilize the numeric quote for quotation marks, I encountered an issue: 'The sole legitimate numeric escape in strict mode is '\0` The snippet of code causing the problem can be seen below: export const Title = styled(Typogra ...

What is the best method for clearing DOM variables and storage when a new innerHTML is loaded dynamically in a Single Page Application?

When I load Dynamic HTMLs with JS into a div on an index page, the content of the div gets updated dynamically based on user actions using the JQuery.load function. The loaded HTML includes JS files that are also added to the DOM and work as expected. How ...

A New Approach to Initializing Web Pages in ASP.NET (with a Surprising Twist)

Well, I've encountered quite the puzzling issue with a project I'm working on (it could even make it to the Daily WTF), and I'm hoping for some help in finding a solution. (Apologies in advance for the lengthy explanation...) About a month ...

Which event listener in the DOM API should I use to trigger an action when a form field is focused, whether through a mouse click or by tabbing?

My aim is to increase the size of form fields when the cursor focuses on them, either through a mouse click or by tabbing using the keyboard. By utilizing document.activeElement focus, I can identify when the user clicks inside a text input or selects an ...

Numerous passcodes needed for easy access to secured webpage

I am currently working on a basic webpage that uses a PHP password script to grant users access. It's functioning perfectly for one user, but now I need to add a second password for another user. If anyone has any suggestions or solutions to this issu ...

utilizing for loop in jQuery

$(document).ready(function() { $for(var i=1;i<8;i++) { $("#"+i).hover(function() { $("#"+i).stop().animate({left:"50px"}); }, function() { $("#"+i).stop().animate({left:"30px"}); }); ...

I am looking to display the precise text from an HTML file while maintaining the original formatting in a Flutter application

When working with Flutter, I am fetching data from an API and need to display its contents. However, some fields include HTML tags. For example, the data I am receiving looks like this - {"id":509,"topic_name":"HTML testing",& ...

Troubleshooting Z-Index Problem in Internet Explorer 7 with CSS Dropdown

Despite trying various solutions with JQuery and CSS Tricks, I'm encountering a problem where my drop-down menu won't display properly over my accordion slider in IE7. This issue doesn't appear in other browsers. Any assistance on resolving ...

Tips for connecting an event to an object for resizing and clicking

I have been working with jQuery version 1.4.1 and attempting to assign resize and click events in this manner, but it does not seem to be functioning as expected. var $elements = []; $elements.window = $(window); $elements.window.bind('resize', ...

Avoid duplicate IDs while concealing content with media query in CSS3

Utilizing bootstrap 4 and vuejs, the desktop version includes a container with a tab pane and map. However, on mobile devices, only the map is displayed without the tab pane. The following code simplifies the issue at hand. The tab pane and map have high ...

The 'refresh' function in jQM listview is causing issues with inset lists

For some reason, I am struggling to understand why this issue is occurring: In jQuery Mobile, I have an unordered list with data-inset="true". Initially, it displays perfectly with rounded top and bottom edges. However, on dynamically adding new elements t ...

What is the best way to horizontally align paragraphs within different divs or spans?

Currently, I have 2 divs placed side by side that each contain about 5 paragraphs. My goal is to align these paragraphs horizontally so that paragraph 2 in the first div starts at the same line as paragraph 2 in the second div (and so on for all other para ...