The size of the <DIV> element turns out to be larger than originally anticipated

First things first, check out this HTML template:

<div id="content">
    <header>...</header>
    <div id="pages">
        <div class="page">...</div>
        <div class="page">...</div>
        <div class="page">...</div>
    </div>
</div>

You'll notice that the pages are located beneath the header and are initially hidden until triggered by JS code.

Everything seems to be functioning fine, however, there's an issue where the page extends beyond the screen height, causing a scrollbar to appear outside the borders of the screen.

+--------------------------+   ---------
| HEADER                   |      |
|                          |      |
*--------------------------*      |
| PAGE                     |      |
| content                  |      | - SCREEN SIZE
| content                 #|      |
| content                 #|      |
| content                 #|      |
+--------------------------+   ---------
| content                 #|
| content                 #|     # signifies the scrollbar
*--------------------------*

Even when the page doesn't have any actual content, it still occupies the full size of the screen.

Here's the relevant CSS:

*, *:after, *:before {
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}

header {
    background-color: #fdc162;
    padding-bottom: 1em;
    height: auto;
}

.page {
    display: block;
    position: absolute;
    width: 100%;
    height: 100%;

    visibility: hidden;
    overflow: auto;
    -webkit-backface-visibility: hidden;
    -moz-backface-visibility: hidden;
    backface-visibility: hidden;
}

So why is this happening, and how can I fix it without relying on JavaScript?

Answer №1

When styling your element with the class .page, try replacing height:100% and width:100% with auto for a more responsive design.

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

React - utilize a variable as the value for an HTML element and update it whenever the variable undergoes a change

I'm on a mission to accomplish the following tasks: 1.) Initialize a variable called X with some text content. 2.) Render an HTML paragraph element that displays the text from variable X. 3.) Include an HTML Input field for users to modify the content ...

tips for dynamically changing the active class

The issue lies in the code at ul-> li -> a ng-click. The "active" class is not changing when clicked. This is the content of my index.html file <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/html"> <head lang="en"> <me ...

Is there a way to implement a bootstrap carousel where only one item moves with a single click?

Having trouble implementing a Bootstrap multi-item carousel with continuous movement after copying code from this source. The effect looks different in my localhost environment. Can anyone provide assistance? Links to CSS and JS Added: <link rel="st ...

Is there a way to preserve all the downloaded node modules in the package.json file?

Is there a way to keep track of all the node modules installed in package.json without the need for reinstalling them? I've heard about running npm init --yes, but I'm not entirely convinced if that will do the trick. Any assistance on this mat ...

Simulating a JavaScript constructor using Sinon.JS

I need to write unit tests for the ES6 class below: // service.js const InternalService = require('internal-service'); class Service { constructor(args) { this.internalService = new InternalService(args); } getData(args) { let ...

Contrast between the functionalities of $.ajax and $.post

$.post( url, data, callback, type ); $.ajax () Is there a distinction between using $.post and $.ajax in jQuery? And if so, which method is recommended? Also, how many parameters can be passed to the $.ajax function? ...

Once invoked by an ajax request, the $().ready function is executed

The functionality of this code is flawless when running on its own. However, once I make an ajax call to it, the code fails to execute. I suspect that the issue lies within $().ready, but I haven't yet identified a suitable replacement. Any suggestio ...

Working with Garber-Irish in Rails: Streamlining Administration and Keeping Code DRY

I am currently implementing the innovative garber-irish technique to organize my JavaScript files. Here's my issue: I have a Model (let's call it Item) with an init function located in app/assets/javascripts/item/item.js For example: MYAPP.ite ...

Automatically update div content using AJAX in a different approach

In my situation, I am facing a unique challenge compared to other queries. I have a div element with the following code <div id="ondiv"><?php ?></div> Within this PHP section are details of people who are currently online. Ideally, when ...

Having trouble getting a NodeJS sample app to start up because it can't locate the 'config' file?

I am currently delving into the world of Node.js and have been attempting to launch a sample application that I recently acquired from a git repository: https://github.com/madhums/node-express-mongoose-demo Despite diligently following all the provided i ...

JavaScript .indexOf array method not functioning properly in Internet Explorer versions 7 and 8

I'm curious to know if IE 7 and IE 8 are compatible with the JavaScript .indexOf() method because I keep getting this error message: SCRIPT438: Object doesn't support property or method 'indexOf' This error appears in the IE9 debug co ...

`Developing reusable TypeScript code for both Node.js and Vue.js`

I'm struggling to figure out the solution for my current setup. Here are the details: Node.js 16.1.x Vue.js 3.x TypeScript 4.2.4 This is how my directory structure looks: Root (Node.js server) shared MySharedFile.ts ui (Vue.js code) MySharedFi ...

Filtering controls within a table are not displayed in VueJS

I have been attempting to implement date filtering in my data table based on a demo I followed. Despite meeting the filter requirements, no results are being displayed which is perplexing. Below are the imports and data from the file containing the table: ...

"Receiving the error message "Headers already sent to the client" when attempting to set headers for private routes in a NodeJS application utilizing JWT authentication

Currently, I am developing a back-end for an online medical consultation application and am facing an issue with JWT authentication. As a beginner in this field, I don't have much knowledge about this topic. In my NodeJS project, I have three routes: ...

Plot the highest-ranked outcomes based on a search using Google Maps

I'm currently facing a challenge in integrating different components. I have successfully created a php page to display results from a mysql database and can also retrieve addresses for mapping with Google. However, I am struggling to combine both fun ...

A pair of large pillars perfectly aligned at the center in both horizontal and vertical position

Can anyone suggest an efficient way to design the following layout with responsiveness in mind? I attempted to divide the elements into sections and applied the transform property, but I encountered difficulties when trying to style the boxes on either si ...

Nodemailer fails to send out emails despite the absence of any error messages

I'm currently working on setting up a confirmation email feature for user sign-ups on my website. I've tackled similar tasks in the past, but this time I've hit a roadblock - the emails are not being sent, and there are no error messages to ...

Transform a dynamic Maya model into JSON format for seamless integration with Three.js

After creating a Maya model in Maya 2008, I need to convert it to a JSON format for use with three.js. I have experimented with different methods including: 1) Utilizing the threeJsFileTranslator.py Maya plugin provided in the threejs package. 2) Trying ...

Unable to modify the title property of a link

Currently, I am in the process of transforming my website to support multiple languages. To achieve this, I have implemented a function using jQuery that dynamically changes text when a language button is clicked. While this method has been successful for ...

Rearranging Divs on Mobile with Bootstrap 4

I've been working on adapting an HTML layout for mobile devices, and one of the challenges I'm facing is rearranging the order of div elements. The current setup for the desktop version looks like this: https://i.sstatic.net/fWeDB.png For the mo ...