Fixed Div with height set to 100% and the ability to scroll

I am trying to create a fixed div that will expand in height as needed, filling the available space. If the content inside exceeds 100% of the height, I want it to be scrollable.

So far, my attempt has been with this CSS:

.container {
  width: 300px;
  max-height: 100%;
  overflow-y: auto; 
  position: fixed;
}

Unfortunately, this approach has not worked for me. Is there a way to achieve this without setting a fixed size in pixels?

Answer №1

When you want to span the full height of the viewport, simply utilize 100vh.

.wrapper {background: blue; height: 100vh;}
<div class="wrapper"></div>

Answer №2

Take a look at this fantastic solution :)

body {
  background-color:blue;
}
.container {
  position:absolute;
  top:0; right:0; bottom:0; left:0;
  overflow-y:scroll;
  background-color:white;
}
.spacer {
  width:15px;
  height:150vh;
  background-color:green;
}
<div class="container">
  <div class="spacer"></div>
</div>

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

Bootstrap 4 responsive Navbar doesn't support dropdown menus

Having trouble getting the dropdown feature of bootstrap's navbar to work. Even after changing the color to black for visibility, I still can't get the menu options to drop down when clicked. Check out the JSFiddle here. Below is the code snippe ...

Placing <object> within the existing HTML form

If a user enters the values 12345 into an input box on my webpage and clicks a button, an object will appear below or instead of the form. The code I have for this functionality is: <form name="form" action="" method="post"> <input type="text" ...

Align text to the left while centering other elements - Cascading Style Sheets - Bootstrap version 4

My initial goal seemed straightforward: to place the description 'Print Flags' on the left side of the box in the image below, with buttons centered on the right: https://i.sstatic.net/n0z7l.png Despite my efforts, this is as close as I've ...

Ensure all input-group-addons have equal width with Bootstrap 4

Can the width of all prepend add-ons be made the same? For example, in this image, I would like Email, License Key 1, & License Key 2 to have equal lengths. Is this achievable? If I were to forgo add-ons and only use regular labels and a form grid, it wo ...

Using PHP, JavaScript is unable to hide <div> elements

I'm encountering an issue where the div I want to show when an error occurs is not hiding and showing properly using JavaScript. Here is a snippet of my code: <script> function hideerror() { var catdiv = document.getElementById(error); ...

In IE11, the letter type list with the style of lower-alpha no longer displays proper indentation

When viewing on IE11, the list in lower-alpha style (list-style-type: lower-alpha) is missing indentation. However, the indentation remains intact when viewed on Chrome, Edge, and Firefox browsers. The code snippet below showcases some of the CSS styles be ...

Unexpected issue encountered for identifiers beginning with a numerical digit

Is it possible to select an element from a page with an id that begins with a number? $('#3|assets_main|ast_module|start-iso-date') Upon attempting to do so, the following error occurs: Uncaught Error: Syntax error, unrecognized expression: ...

Tips for keeping the footer consistently at the bottom of the page without using a fixed position (to avoid overlapping with the main content)

I've been struggling to keep the footer at the bottom of my webpage. I came across a solution online suggesting to use fixed CSS positioning. However, when I applied this fix, the footer ended up overlapping with the actual content on the page. Is the ...

How to Align col-md-5 in the Center Using Bootstrap?

Is anyone else struggling with this dilemma or is it just me? I've been searching everywhere for a solution to my problem but I can't seem to find one. According to the grid system, if you have a column size of col-md-5, centering it should be ...

Updated INNER header and footer - unrelated to the answered questions

After observing, the inner-header and inner-footer div scroll along with the area that contains the select list. How can I make that area scroll down while keeping the inner-header/footer fixed within the content? I hope my query is understandable. Thank ...

Sync HTML Videos

Issue: I am currently developing a 3 column layout where certain columns need to remain sticky at the top of the viewport. In one section, I want to use the same video as a background for all 3 columns, with the specific effect of having the middle column ...

Navigating through pages using << >>, Previous, and Last buttons while preventing infinite scrolling

This particular code snippet is designed to generate a new page for every set of 8 div elements. pageSize = 8; showPage = function(page) { $('.line-content').hide(); $('.line-content:gt('+((page-1)*pageSize)+'):lt('+(p ...

How can you position an absolute DIV with an unknown height outside of a "relative" parent using CSS?

Imagine a straightforward illustration using html: <div class="parent"> <div class="child"> </div> </div> and CSS: .parent{ position:relative; background:red; width:200px; height:40px; } .child{ positi ...

Choose tag using position in a sequence

I am working on updating the label text "E-mail" to say "User Name" in this HTML markup. The only tool I have access to for this task is jQuery. <div class="foo" style="border:1px solid #444"> <span class="field-with-fancyplaceholde ...

Tips for positioning an element at the bottom of columns using bootstrap

I'm having trouble aligning an image to the bottom of the page. Despite the column being the same height, the image just won't align all the way to the bottom. https://i.sstatic.net/0u9LH.jpg Check out the Codepen demo for reference: https://co ...

Beautiful ExpressionChangedAfterItHasBeenCheckedError

I need your help Input field where I can enter a Student email or IAM, which will be added to a string array List displaying all the students I have added, using a for loop as shown below Delete button to remove a student from the array The list has a sp ...

The Mystery of Bootstrap 4 Column Sequence

I was able to achieve this layout using Bootstrap 3, but I am not sure how to implement the same setup with Bootstrap 4 (4.1). My goal is to have a column displaying C beneath A, and another column displaying B. However, on mobile devices, I want all thre ...

Implementing snow animation exclusively to a targeted div

I found some helpful code at and now I'm facing an issue where the snow effect is falling all over my page instead of just within the banner div... // Storing Snowflake objects in an array var snowflakes = []; // Browser window size variables v ...

Text adornments persisting even after formatting removal (underline disappears, but text remains embellished)

I included a link within a div and applied text-decoration: none; to the anchor tag as shown below: Here is the CSS (SCSS) code snippet used: &__link { &:link, &:visited { text-decoration: none; } } And here is the corres ...

Background image spacing

Can anyone explain why there is extra space after my background image in this code snippet? (red line in image highlights the spacing issue) Even though the background image doesn't have this space, it seems to extend beyond where the black color ends ...