Unable to reach the bottom due to fixed div placement with offset

There's a fixed sidebar div that is offset by using top: 90px. However, it seems that you can't scroll all the way down in this div. Interestingly, if you change the offset to top: 0px;, everything works as expected.

body {
  font: 76%/150% Arial, Helvetica, sans-serif;
  color: #666;
  width: 100%;
  height: 100%;
}
#sidebar {
  position: fixed;
  top: 90px;
  left: 0;
  width: 20%;
  height: 100%;
  background: #EEE;
  overflow: auto;
}
#content {
  width: 80%;
  padding-left: 20%;
}
@media screen and (max-height: 200px) {
  #sidebar {
    color: blue;
    font-size: 50%;
  }
}
<div id="sidebar">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer lacinia libero eget mi rhoncus laoreet. In hac habitasse platea dictumst. Etiam placerat congue mi quis feugiat. Aliquam placerat sagittis consectetur. Nulla iaculis tincidunt leo vel luctus.
  Pellentesque euismod tincidunt diam, quis porta erat laoreet a. Mauris pellentesque purus ac eros elementum et rutrum orci iaculis. Morbi tincidunt posuere nulla a commodo. Curabitur eu ligula diam. Pellentesque fringilla, felis in tincidunt adipiscing,
  nisi eros consectetur felis, quis sollicitudin purus quam ut metus. Integer imperdiet nulla id diam ultricies ut ultricies nisl eleifend. Duis tortor tellus, laoreet nec pellentesque ut, euismod non lectus.</div>
<div id="content">Cras gravida, diam non adipiscing cursus, sapien urna adipiscing enim, at faucibus nunc felis at turpis. Aliquam erat volutpat. Nulla facilisi. Aenean nec nisi gravida ante convallis euismod sed quis odio. Sed nulla est, fringilla vel rhoncus vel, fermentum
  et turpis. Curabitur eu posuere tortor. Integer sit amet nisl elit, gravida rutrum ipsum. Cras nisl est, sodales quis faucibus nec, tempus vel libero. Aliquam lobortis gravida erat, in placerat libero ultricies in. Curabitur volutpat lorem ut ligula
  aliquet a fermentum augue porttitor. Vestibulum varius, purus id sollicitudin tincidunt, velit felis tincidunt erat, ut feugiat augue diam commodo lorem. Donec in augue non est tincidunt consequat. Mauris nec justo eget augue varius pulvinar id ut risus.
  Donec fringilla, enim vitae tincidunt accumsan, urna elit laoreet tellus, ac gravida dolor dolor ac quam. Vestibulum dignissim felis quis tortor sollicitudin ut placerat mi adipiscing.</div>

JSFiddle

If I want to maintain top: 90px; and still be able to scroll to the bottom, what adjustments do I need to make?

Answer №1

The main issue here is that the #sidebar element is set to have a height: 100%;. This causes it to take up the entire height of the viewport, resulting in the bottom part of the div being hidden when you offset the top by 90px.

To resolve this problem, one solution is to use the calc function to subtract the 90px offset from the height.

  • To fix this issue, modify the #sidebar CSS rule to change height: 100%; to height: calc(100% - 90px);

body {
  font: 76%/150% Arial, Helvetica, sans-serif;
  color: #666;
  width: 100%;
  height: 100%;
}
#sidebar {
  position: fixed;
  top: 90px;
  left: 0;
  width: 20%;
  height: calc(100% - 90px);
  background: #EEE;
  overflow: auto;
}
#content {
  width: 80%;
  padding-left: 20%;
}
@media screen and (max-height: 200px) {
  #sidebar {
    color: blue;
    font-size: 50%;
  }
}
<div id="sidebar">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer lacinia libero eget mi rhoncus laoreet. In hac habitasse platea dictumst. Etiam placerat congue mi quis feugiat. Aliquam placerat sagittis consectetur. Nulla iaculis tincidunt leo vel luctus.
  Pellentesque euismod tincidunt diam, quis porta erat laoreet a. Mauris pellentesque purus ac eros elementum et rutrum orci iaculis. Morbi tincidunt posuere nulla a commodo. Curabitur eu ligula diam. Pellentesque fringilla, felis in tincidunt adipiscing,
  nisi eros consectetur felis, quis sollicitudin purus quam ut metus. Integer imperdiet nulla id diam ultricies ut ultricies nisl eleifend. Duis tortor tellus, laoreet nec pellentesque ut, euismod non lectus.</div>
<div id="content">Cras gravida, diam non adipiscing cursus, sapien urna adipiscing enim, at faucibus nunc felis at turpis. Aliquam erat volutpat. Nulla facilisi. Aenean nec nisi gravida ante convallis euismod sed quis odio. Sed nulla est, fringilla vel rhoncus vel, fermentum
  et turpis. Curabitur eu posuere tortor. Integer sit amet nisl elit, gravida rutrum ipsum. Cras nisl est, sodales quis faucibus nec, tempus vel libero. Aliquam lobortis gravida erat, in placerat libero ultricies in. Curabitur volutpat lorem ut ligula
  aliquet a fermentum augue porttitor. Vestibulum varius, purus id sollicitudin tincidunt, velit felis tincidunt erat, ut feugiat augue diam commodo lorem. Donec in augue non est tincidunt consequat. Mauris nec justo eget augue varius pulvinar id ut risus.
  Donec fringilla, enim vitae tincidunt accumsan, urna elit laoreet tellus, ac gravida dolor dolor ac quam. Vestibulum dignissim felis quis tortor sollicitudin ut placerat mi adipiscing.</div>

Answer №2

Kindly update the CSS link provided below. This will ensure your DIV remains fixed at the bottom with an automatic 90px space from the top.

#sidebar {
    position: fixed;
    bottom: 0px;
    left: 0;
    width: 20%;
    height: calc(100% - 90px);
    background: #EEE;
    overflow: auto;
}

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

Adjust and resize video backgrounds within parent elements on iframes

Consider the code snippet below: <div class="viewport"> <iframe src="youtube.com/blabla"></iframe> </div> Accompanied by this CSS: .viewport { height: 100vh; width: 100%; } iframe { position: absolute; } If we t ...

Ensuring that the text-box is the same size as the image

I am encountering two challenges: When scaling the window down horizontally, I am facing an issue with aligning the images on the left (sideImage) vertically with the text box. I have attempted using margin-top auto and margin-bottom auto, but that doe ...

Horizontal Scroll HTML

Currently in the process of building a website for my father, everything is going smoothly. I followed a helpful Stackoverflow tutorial to create a specific webpage that I now want to customize with a hyperlink and make it scroll horizontally: Sliding divs ...

The container div with a gradient background doesn't support the use of height: auto

Currently, I am faced with the challenge of addressing this particular issue: The outer div ("container") is not allowing height:auto and instead conceals the entire content within the div - however, it is crucial for me that the outer div expands as it w ...

What is the best way to generate a variable amount of div elements with constantly changing content using Angular2?

I'm not entirely sure on the process, but I believe ngFor would be used in this scenario. Essentially, my goal is to generate the following div multiple times, with each iteration updating the value inside the brackets from 0 to 1, 2, and so forth... ...

Reordering divs in one column with CSS Flexbox to transition to a two-column layout upon resizing the screen

Exploring the world of Flexbox, I'm not entirely convinced it's the right solution for my layout challenges. Here's what I have in mind: In a 940px wide space, I need to create three columns with fixed widths of 300px each. However, on medi ...

Place the second division beneath the first within a single navigation bar that adjusts accordingly to all screen sizes

I am experiencing an issue with the layout of my page that has 2 divs within one nav element. When the screen width is greater than 1024px, everything looks fine. However, when I reduce the width to less than 768px, the two divs merge into one line instead ...

Capture audio using a web browser

Currently working on a project to create a platform for recording sounds. I'm aiming to incorporate a meter that measures the volume of the sound. Despite extensive research, I haven't been able to discover an HTML5 solution compatible with all b ...

Tips for showcasing heading and paragraph elements side by side in css?

I have a block of HTML code that includes a heading and two paragraphs: <div class="inter"> <h4>Note</h4> <p>To add/remove a dependent or to modify your spouse's insurer information, go to the My Life Events section and foll ...

Showing a series of text entries one after the other, each appearing with a smooth fade-in and fade-out

I am eager to showcase a list of text in a sequential order, implementing a fade-in/fade-out effect and concluding with the display of an image. Additionally, I aim to have all the text centered on the page. <div>a<div> <div>b</div> ...

Utilize the CSS content property to embed an image without causing it to distort in size

Struggling to swap out one image for another without stretching it? In my demo, I replaced an elephant with a lion using only CSS - no changes allowed to the HTML. Unfortunately, the lion image ends up stretched. Even adding background-size: cover doesn&ap ...

When using PHP code, the col-md-4 divs are positioned vertically instead of horizontally

I have written PHP code that seems to be working correctly, but the "col-md-4" divs are not aligning next to each other as expected. Instead, they appear one below the other. Could someone please assist me in identifying what I may have done incorrectly? ...

Create a slider feature on a webpage using the Google Maps API

A webpage has been created using the Google Map API. JSfiddle function initMap() { var intervalForAnimation; var count = 0; var map = new google.maps.Map(document.getElementById('map'), { cen ...

Is the HTML5 capture attribute compatible with wkwebview?

Is it supported as stated in the title? For more information, you can check out the MDN documentation (Incomplete) and the Caniuse list of supported browsers. Surprisingly, none of them mention wkwebview. Does this attribute have support in wkwebview? Kno ...

Modify the image inside a div when hovering

How can I create a product card that displays thumbnails of images when hovered over, and changes the main image to the thumbnail image? My current challenge is getting this functionality to work individually for each card on an e-commerce site. Currently, ...

On the initial click of the button, the color will switch, and on the subsequent click,

I have created a basic HTML structure with a paragraph and a button. Upon clicking the button, I need different actions to take place. Specifically, on the first click, I want to change the color of the paragraph. On the second click, I aim to alter the fo ...

Tips for Implementing CSS Styles on Ruby on Rails HTML Pages

Just starting out with RoR and trying to customize my form with CSS classes. Here's what I have so far: <%= form_tag :action => 'create' do %> <p><label for = "name">Name</label>: <%= text_field ...

Determination of the input parameters

Currently, I am developing an Angular application that includes a matInput field for user input. The issue I am encountering is that when the user enters a positive or negative value in the field (e.g. +5 or -5), the final output does not reflect the inten ...

Confirm that only the days of the present month are eligible for selection

I have been given the responsibility of validating a date field that is populated when an invoice is created. The date field consists of a text box and three button objects allowing users to select a date from a calendar, input today's date, or remove ...

Tips for vertically aligning input field text and checkboxes

I need help aligning a checkbox vertically in the middle of an input field and checkbox that are in the same row. Here is the current code snippet: <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" in ...