What is the most effective way to utilize CSS in order to contain a page filled with tall nested elements within the height of the viewport?

How can I restrict a page to the height of the viewport? I want to control the overflow-y on child elements, but it seems like I cannot limit the height--I can only set a max-height in pixels or a percentage. I believe I need to confine the height of certain elements to the remaining portion (not a percentage) of the viewport height, but I am unable to find a solution for that.

(I am utilizing bootstrap, however, I suspect the solution does not revolve around bootstrap.)

I thought about using flex with flex-grow, but even that doesn't limit the height. What am I overlooking?

<div class="container d-flex flex-column ">
 <div>
 My full-width page title goes here 
 </div>
  <div class="row flex-grow-1">
    <div class="col col-4">
      potentially long content here
    </div>
    <div class="col-8">
     main content 
    </div>
  </div>
</div>

Using CSS

body {
  height: 100vh;
}

.row {
  margin-top: 20px;
}

.col {
  border: solid 1px black;
  padding: 10px;
  overflow-y: scroll;
}

(Fiddle)

Current: Page extends beyond viewport height; inner scroll bar is ineffective; viewport scroll bar present

Desired: Page utilizes entire viewport height and no more; functional inner scroll bar; no viewport scroll bar

Answer №1

If you're open to alternatives other than bootstrap/flexbox, utilizing CSS grid can simplify the layout process.

HTML

<div class="container">
   <div class="top-section">
     Insert your full-width page title here
   </div>
   <div class="side-content">
      Sidebar goes here
    </div>
    <div class="main-content">
     Main content area
    </div>
</div>

CSS

html, body, .container {
  height: 100%;
}

.container {
  display: grid;
  grid-template-columns: 1fr 2fr;
  grid-auto-rows: min-content auto;
  grid-template-areas: 
    "top top"
    "sidebar main";
}

.top-section {
  grid-area: top;
  background: red;
}

.side-content {
  grid-area: sidebar;
  overflow: auto;
}

.main-content {
  grid-area: main;
}

Live demo

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

Removing a CSS class using JQuery

Within my website layout, I have a div that is dynamically included using PHP. This div is inserted in two different locations, each inside its own parent div. <div id="parent_div"> <div id="contact_details_div" class="contact_details_div sam ...

What is the process for spinning a span in the center of an image?

My canvas displays an image: https://i.sstatic.net/p3MV4.png There is a white square with a refresh icon on the right side of the image, slightly hidden by a black circle. I implemented it like this: var rotatorSpan = document.createElement("span"); rot ...

Content will be displayed below the background image

Help Needed: Content Going Over Background Image Hey there! I'm having a bit of trouble with my home page design. I have a full-width background image, but the content isn't displaying below it like I want it to. Instead, it's showing over ...

Creating a water vessel design using CSS

Despite going through the JS tutorial, I still struggle with it and need some assistance. I believe using a jsfiddle would be helpful. I am attempting to use JS to create a small box that changes color from green to empty based on the fullness of a "wate ...

Wide container using Bootstrap

Currently, I am incorporating Bootstrap v5 alpha to develop a basic dashboard. According to Bootstrap guidelines, it is essential to utilize .container, .container-fluid, or .container-{size}, followed by .row and .col columns. However, I wish for the das ...

Material UI causing animation to fail to trigger

After integrating material UI into my existing application, I encountered a peculiar issue. When adding material UI components to modals, the entering animation fails to trigger. Interestingly, downgrading material UI or removing all MUI components resolve ...

What is the best way to access the 'hidden' property for a div using crispy forms?

I am trying to figure out how to make 'hidden' a property of a div in my HTML: <div class="some-class" hidden> <input id="field1"....... form stuff> </div> If I have a form set up like this: class SomeForm(forms.ModelForm ...

Opacity effect on input text when it exceeds the input boundaries

I'm having an issue: I need to create inputs with different states, including when the text is longer than the input itself. In this case, the extra text should fade out with a gradient transparency effect: https://i.sstatic.net/r5qQu.jpg Here is my ...

I would like to style the input checkbox using CSS

Is there a way to style input checkboxes with CSS that will work on all browsers (Chrome, Firefox, IE 6, 7, and 8)? If jQuery is the only solution, please let me know. It needs to be compatible with all browsers. Can anyone provide guidance on how to ach ...

What is the best way to align the text next to the initial input and expand the text close to the second input field?

I am an avid user of Bootstrap 4. BC stands as a global pioneer in online news and information, striving to educate, engage, and empower individuals worldwide. - this content should be positioned to the right of the top input field. https://i.sstatic.n ...

The Radio button and Checkbox values are causing an issue where the Radio button is continuously summing upon clicking without a limit. Why is this happening? Check out

I'm currently stuck in a function and believe it would be helpful for you to guide me along the correct path. My goal is to sum the values of checked boxes with the values of checked radio buttons. However, the radio values are continuously accumulat ...

Trouble with HTML2PDF.js - download not being initiated

Currently, I am utilizing html2pdf.js in my project by following this tutorial: https://github.com/eKoopmans/html2pdf.js However, I've encountered an issue where despite implementing everything as instructed, the download prompt for the specified div ...

Align a button to the left or right based on its position within the layout

On the left side, there is dynamic text and on the right side, a button is displayed as shown below: <div class="dynamic-text"> {{ dynamicText }} </div> <div class="some-button"> < ...

Showing various records dynamically with AngularJS

I have some AngularJS Code below where I am currently adding four records to roleList. However, I would like to be able to add any number of records to roleList. Is there a way for me to achieve this? $scope.roleList = [ {"companyName": "Company 01" ...

Trying to reduce the cursor box area within an A link containing a div box

My communication skills are lacking, so I have included an image to better illustrate my issue. Here is the problem .body { text-align: center; display: flex; flex-direction: column; align-items: center; } .flex-container { display: flex; ...

Overlap of Bootstrap 4 checkboxes and radio buttons within a modal window

I've been struggling to troubleshoot my code for hours and it seems like I could use some fresh eyes on it. The issue I'm facing involves trying to vertically align a checkbox followed by two radio buttons inside a modal using Bootstrap 4. I had ...

What is the best way to insert a <dv> element following a <Typography> component in the provided code?

After learning React, I have attempted in various ways to get this code snippet to work. I referred to a question on Stackoverflow as well as the HTML div documentation The goal is to have the text and link displayed in a horizontal line, not vertically s ...

Issue with updating onclick attribute of popover in Bootstrap 4

My goal is to design a popover in bootstrap 4 with a nested button inside it. However, when I update the data-content attribute of the popover with the button element, the element gets updated but the onclick attribute goes missing. I have experimented wi ...

Scrolling through the page, press the "Read Less"

I've implemented a Read More/Read Less button feature for product descriptions on my website. One issue I'm facing is that when I click the Read Less button at the bottom of the extended description, the text shortens as expected but the page do ...

VueJS3 and Vuetify are in need of some additional CSS classes

We are currently in the process of upgrading our application from old VueJS+Vuetify to VueJS3. However, we have encountered some classes defined in the template that are not available in the new version. These classes include xs12 (which is intended to co ...