What is the best method for achieving a div that is 100% height in relation to the screen while also having a `top

My div element is set with a top='70px' property. However, when the div has content that requires scrolling, it moves down and the end of the scroll is not visible.
I tried adding the following properties to the div, but it did not resolve the issue:

div {
    max-height: 100vh;
    overflow: auto;
}

For example:

*, *::before, *::after {
    padding: 0;
    margin: 0;
    border: 0;
    box-sizing: border-box;
}

div {
    position: fixed;
    top: 70px;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    padding: 30px 30px 30px 30px;  
    max-height: 100vh;
    overflow: auto;
}

div::before {
  content: "";
  position: fixed;
  width: 100%;
  top: 0;
  left: 0;
  height: 70px;
  background-color: #222;
  z-index: 2;
}
<div>
  <ul>
    <li><a href="">Section #1</a></li>
    <li><a href="">Section #2</a></li>
    <li><a href="">Section #3</a></li>
    <li><a href="">Page #1</a></li>
    <li><a href="">Page #2</a></li>
    <li><a href="">Page #3</a></li>
    <li><a href="">Page #4</a></li>
    <li><a href="">Page #5</a></li>
    <li><a href="">Page #6</a></li>
  </ul>
</div>

Answer №1

You have the option to employ the calc() function in order to deduct the div's top value from the total height of the screen; see an example below:

div {
  top: 70px;
  height: calc(100vh - 70px);
}

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

Utilizing Flexbox for Spacing

When utilizing flex containers, is it considered safe and acceptable to apply margin-top, margin-bottom, margin-left, margin-right, and padding to create a little space between elements or shift them to the left or right? Or is it more advisable to use f ...

Ways to implement the tabIndex attribute in JSX

As per the guidelines provided in the react documentation, this code snippet is expected to function properly. <div tabIndex="0"></div> However, upon testing it myself, I encountered an issue where the input was not working as intended and ...

What is the best method for eliminating underscores from text that is hyperlinked in a locally hosted HTML file?

I recently encountered an issue with my HTML file where the text "Indian" became underlined after saving the file. Here is the code snippet: <a href="file:///G:\work files\project\indian.html" target="_blank"> <div class="button ...

Closing the Bootstrap 5 Navbar on Click Event

I'm not very familiar with Bootstrap and I came across this code online that involves javascript in html, which I don't fully understand. I want to make the hamburger menu close automatically after selecting an item in the navigation bar, especia ...

How come an element retrieved with getElementById in Next.js comes back as null despite the presence of a defined document?

Having trouble using SSR in my React/Next app. Despite having the document present (and being able to visually see the div with the id plTable), the getElementById function is returning null. I even tried calling getElementById after 6 seconds to ensure ...

Leveraging backstretch.js in combination with blur.js (or equivalent)

Query Update I provided a response to the query below, however, I am experiencing some lag and a noticeable stepped transition between images. Can anyone offer advice on how to optimize this issue? Perhaps it would be better to go back to using a static ...

Guide to setting up a nested vuetify navigation drawer

I am facing a scenario where I have one fixed navigation drawer with icons and another dynamic navigation drawer that should open and close adjacent to the fixed one without overlapping. The current implementation is causing the dynamic drawer to overlap t ...

Tips for extending hover duration in CSS

a:hover + #menu { display: block; position: fixed; } My CSS for a hover effect is causing the menu to disappear quickly once I move the mouse away. What steps can I take to fix this issue? Would utilizing JavaScript provide a better solution, and if so, ...

Layer several divs inside a main div

I'm grappling with a simple issue and could use some help to resolve it. Utilizing bootstrap, below is my CSS and div structure. How can I achieve an overlap of DIV 1, DIV 2, and DIV 3? Essentially, I want to position them on the same level, one behi ...

Uncovering unseen tags generated by JavaScript on a webpage using Python

I have THIS LINK page that contains javascript. To view the javascript, simply click on show details. How can I extract data from this URL source? Should I use re? Here is what I attempted with re: import urllib import re gdoc = urllib.urlopen('Tha ...

Scraping specific section of text from a webpage's source code with BeautifulSoup library in Python

As a novice in python, I have little to no knowledge of HTML. After stumbling upon a captivating youtube video (https://www.youtube.com/watch?v=kEItYHtqQUg&ab_channel=edureka%21) on web scraping, I became intrigued by the idea of extracting text from U ...

Is your React application struggling to display large images when bundled with Webpack?

I am facing an issue while trying to display an image from my image folder in a React project using Webpack. I have observed that smaller photos with physically smaller dimensions and file sizes load properly, but larger photos do not render on the screen, ...

What could be causing my CSS dropdown menu to not display properly?

I'm having trouble getting the dropdown to work when hovering over the li element with "portfolio" in the text. The code seems correct, but nothing happens when I try to hover over "Portfolio." Below is the code snippet: #navmenu ul { position: ...

What is the process for modifying the django password reset confirmation page?

As a fresh Django developer, my goal is to customize the django password_reset_confirm.html page with a new HTML file called change_pwd.html. <!DOCTYPE html> {% load static %} <html lang="en"> <head> <meta http-equiv="Conte ...

Adjust the height of images to be consistent

I'm currently working on creating a grid layout with 4 images in a row using DaisyUI card component. However, I've run into an issue where there is white space at the bottom of some images due to varying image heights. Is there a solution that wo ...

Modify the td attributes while retaining the extracted data values from the website

I'm currently utilizing this code to extract data from another website: $searchURL = "http://www.anotherwebsite.com"; $html = file_get_contents($searchURL); $patternform = '/(<tbody.*<\/tbody>)/sm'; preg_match_all($patternfor ...

Transmitting Chosen Information from One Webpage to Another in HTML

I have a form that passes data from one page to another when the apply button is clicked. The goal is to display the corresponding career title (such as Java Developer) on the next page. I attempted to accomplish this using JavaScript. career.html: <f ...

The string obtained from input.getAttribute('value') is lacking one character

While developing e2e-tests for an angular application, I encountered a puzzling issue. When trying to retrieve the value from an using the .getAttribute('value') method, I noticed that a single character was missing. Checking the HTML properties ...

Eliminate certain inline styles using jQuery

I am facing an issue with an asp menu I am using. It is automatically inserting style="width:3px;" into my menu table tds, creating an unsightly gap between my tabs. Instead of asking our developer to customize the menu just to fix this cosmetic flaw, I am ...

`ASP.NET utilized for displaying several pictures on a website`

My goal is to retrieve images from a database and showcase them on a webpage. I am looking to incorporate a "show more images" button in case there are too many images to display at once. Additionally, I would like for the additional images to load autom ...