When scrolling down a webpage, the background color of the content does not stretch along with the page

I've created a webpage with a sticky header and footer, along with a scrollbar on the main content. However, I'm facing an issue where the background color of the content does not extend beyond the viewport when scrolling down. The text is visible while scrolling, but not the entire background color. The content area is styled in green.

/******************************************************************************/
/*                                  MAIN BODY                                 */
/******************************************************************************/
    :root {
        --background-color: #fbedcf;
        --primary-color: #77037B;
        --label-color: #210062;
        --secondary-color: #009FBD;
        --white-color: #FFFFFF;
        --black-color: #000000;
    }

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

    html, body {
        margin: 0;
        height: 100%;
        font-family: Roboto serif; /* Bootstrap uses a base font size of 16px */
    }
    body {
        min-height: 100vh;
        overflow-x: hidden;
        overflow-y: hidden;
    }

    .page {
        height: 100vh;
        width: 100%;
        border-top: solid 50px transparent;
        border-bottom: solid 50px transparent;
        overflow-y: auto;
        background-color: var(--background-color);
    }

    .content {
        height: 100%;
        background-color: green;
        margin-left: 15%;
        margin-right: 15%;
    }
    p {
        color: var(--label-color);
    }

    /******************************************************************************/
/*                                    HEADER                                 */             
/****************************************************************************/
    header {
        position: fixed;
        z-index: 98;
        width: 100%;
        height: 50px;
        background-color: var(--primary-color);
        text-align: center;
    }

    #header-title {
        margin: auto;
        font-family: Roboto, serif;
        font-weight: bold;
        text-align: center;
        color: var(--background-color);
        letter-spacing: 0.03em;
        font-size: 140%;
        line-height: 50px;
    }

    /********************************************************************/
    /*                           FOOTER                                */
    /*******************************************************************/
    footer {
        position: fixed;
        bottom:0;
        width:100%;
        margin-top: auto;
        background-color: var(--background-color);
        color: var(--black-color);
    }

    .footer-label {
        color:var(--primary-color);
        font-size: 70%;
        line-height: 24px;
    }

    #line-div {
        border-top: 1px solid #999;
        margin-right: 24px;
    }

    #copywrite-div {
        display: flex;
        justify-content: flex-end;
        background-color: pink;
    }
    #copywrite-label-div {
        margin-right: 10px;
    }
    .footer-button {
        border: none;
        background-color: #FFF;
        border-left: 1px solid #999;
        border-top: 1px solid #999;
        width: 24px;
        height: 24px;
        border-radius: 5px 0 0 0;
    }

    .footer-advertisement {
        display: block;
        text-align: center;
        width: 100%;
        height: 50px;
        background-color: var(--white-color);
    }

    .footer-ad-rectangle {
        margin: 0 auto;
        font-size: 70%;
        width: 320px;
        height: 50px;
        line-height: 50px;
        background-color: var(--white-color);
    }
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
    <!DOCTYPE html>
    <html>
    <head>
        <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="80e2efeff4f3f4f2e1f0c0b5aeb1aeb3">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet"
              integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
        <link rel="stylesheet" href="main.css"/>
        <title>JSP - Hello World</title>
    </head>

    <body>
    <!-------------------------------------- START -------------------------->
    <header>
        <div id="header-title">THIS IS THE HEADER</div>
    </header>

    <div class="page">
        <div class="content">
            <p>THIS IS THE BEGINNING</p>
            ...

    </footer>


    <!--------------------------------------- END ------------------------------>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="91f3fefee5e2e5e3f0e1d1a4bfa0bfa2">[email protected]</a>/dist/js/bootstrap.bundle.min.js"
            integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
    </body>
    </html>

Answer №1

Solution for the Issue and How to Resolve it

Here is the CSS code snippet for your .content div.

.content {
    /* height: 100%; remove this. */
    background-color: green;
    margin-left: 15%;
    margin-right: 15%;
}

The property height: 100%; restricts the height of the .content div to 100%, limiting its stretching capability to the end of the text within. By removing this property, you can achieve the desired outcome.

Updated Code Snippet

/* Main Body */
    :root {
        --background-color: #fbedcf;
        --primary-color: #77037B;
        --label-color: #210062;
        --secondary-color: #009FBD;
        --white-color: #FFFFFF;
        --black-color: #000000;
    }

    * {
        box-sizing: border-box;
        margin: 0;
        padding: 0;
    }
    
    html, body {
        margin: 0;
        height: 100%;
        font-family: Roboto serif; 
    }

    .page {
        height: 100vh;
        width: 100%;
        border-top: solid 50px transparent;
        border-bottom: solid 50px transparent;
        overflow-y: auto;
        background-color: var(--background-color);
    }

    .content {
        background-color: green;
        margin-left: 15%;
        margin-right: 15%;
    }
    p {
        color: var(--label-color);
    }

    /* Header */
    header {
        position: fixed;
        z-index: 98;
        width: 100%;
        height: 50px;
        background-color: var(--primary-color);
        text-align: center;
    }

    #header-title {
        margin: auto;
        font-family: Roboto, serif;
        font-weight: bold;
        text-align: center;
        color: var(--background-color);
        letter-spacing: 0.03em;
        font-size: 140%;
        line-height: 50px;
    }

    /* Footer */
    footer {
        position: fixed;
        bottom:0;
        width:100%;
        margin-top: auto;
        background-color: var(--background-color);
        color: var(--black-color);
    }

     .footer-label {
         color:var(--primary-color);
         font-size: 70%;
         line-height: 24px;
     }

     #line-div {
         border-top: 1px solid #999;
         margin-right: 24px;
     }

      ...

<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
    <!DOCTYPE html>
    <html>
    <head>
        <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="482a27273c3b3c3a2938087d6679667b">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet"
              integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
        <link rel="stylesheet" href="main.css"/>
        <title>JSP - Hello World</title>
    </head>

    <body>
    <!-- Page Content -->
    <header>
        <div id="header-title">THIS IS THE HEADER</div>
    </header>

    <div class="page">
        <div class="content">
            <p>THIS IS THE BEGINNING</p>
             ...
          <p>THE END THE END</p>

        </div>  <!-- end content -->

    </div> <!-- end page -->

    <footer>
        <div id="copywrite-div">
            <div id="copywrite-label-div">
                <div class="footer-label">Copyright &copy; 2024 - Yogi Bear</div>
            </div>
            <button class="footer-button" id="close-footer-ad-button">X</button>
        </div>

        <div id="line-div"></div>

        <div class="footer-advertisement" id="footer-ad">
            <div class="line-div"></div>
            <div class="footer-ad-rectangle"> Advertisement</div>
        </div>
    </footer>


    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="20424f4f54535452415060150e110e13">[email protected]</a>/dist/js/bootstrap.bundle.min.js"
            integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
    </body>
    </html>

Get ready to dive into coding! :)

Answer №2

Using height: 100% will fill the entire height of the parent element, which in this case is set to a height of 100vh. If you want the height to be equal to the height of its children, you can use either height: fit-content or height: max-content.

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

What is the best way to preload all videos on my website and across different pages?

I specialize in creating video websites using HTML5 with the <video> tag. On my personal computer, the website transitions (fadeIn and fadeOut) smoothly. However, on my server, each page seems to take too long to load because the videos start preloa ...

Transfer an HTML file generated in real-time to an external server using SFTP

I am currently working on creating an HTML file dynamically using the file_put_contents function and the ssh2 library for SFTP. However, I am facing an issue where Apache is reporting that the file cannot be sent because it does not exist on the local dis ...

Can the .scroll function be turned off when a user clicks on an anchor link that causes the page to scroll?

I am currently developing a timeline page and I want to implement a feature similar to the chronological list of years displayed on the right side of this webpage: As part of this feature, I have set up a click event which adds a circle border around the ...

Utilizing cheerio to set outerHTML in HTML

Could someone kindly assist me with setting the outerHTML of an element using cheerio? I seem to be encountering some issues with this process. For example, let's consider the following HTML structure: <div class="page-info"> <s ...

Finding solutions for activating items and setting data sources in Bootstrap carousel thumbnails for Wordpress

I recently attempted to incorporate a bootstrap-powered carousel with thumbnails into my product slider. I managed to get it working for the main image (large image), but ran into issues when trying to resolve problems with the thumbnail section. Here is ...

Determining the dimensions of a div with a scrollbar using Jquery

Is there a way to get the width and height of a div with scroll that includes both visible and hidden content using JQuery? If anyone has a solution for getting these values, please share. <div id="area" class="divLeftCem area"> <div id="pan ...

Bringing in CSS variables to a Typescript document

In order to streamline the styling process for our app, we have established a theme.css :root file containing a set of commonly used variables that can be accessed across all other .css files. However, some of our older code follows a similar structure bu ...

The button must be programmed to remove a specific item from the server

I am currently developing an application to monitor my expenses using javascript, nodejs, express, and handlebars as the templating engine. Within the app, I have a "list" div that displays all of my expenses. (There is an add button next to the list, not ...

I have been attempting to implement validation in JQuery, but it doesn't seem to be functioning correctly

Can someone assist me with adding validation in jQuery? I'm stuck and need help solving this problem. $(function(){ $("#btn").click(function(){ var b=prompt("Enter your link"); $("a").attr("href",b); if($("b").v ...

Using HTML and JavaScript allows for the video URL to seamlessly open in the default video player app on the device

Working on my mediaplayer website, I want to give users the option to choose which app to play their uploaded videos with. So far, I've attempted to implement a button that triggers this action: window.open("video.mkv", '_blank'); Howeve ...

Prevent anchor jumping caused by popstate event in Safari

This situation is really testing my patience. When navigating within the same page using anchors, the browser automatically takes you back/forward to the location of that link in your history when popstate is triggered. One might think that you could prev ...

Using Express to Deliver Static Content to Subdirectories

I am currently using Express to serve a React application that was bootstrapped with Create React App. The project has the following directory structure: |--client/ | |--build/ | | |--static/ | | | |--main.css | | | |--main.js | ...

What's the Hold-Up with IntersectionObserver in Brackets?

As a novice in the world of web development, I have been utilizing Brackets as my main tool. Recently, I've encountered a few hurdles specifically related to javascript. One issue I'm facing is trying to implement lazy loading on a div containing ...

Positioning of Responsive Slider

I'm currently working on a responsive website, but I am facing challenges with the placement of the slideshow dots. When I switch to the device toolbar, they seem to change position. I have tried various methods such as using relative and absolute uni ...

How can I make my navbar visible once a specific section has been reached?

Is there a way to conditionally display my navbar in react only when a specific section is reached? Currently, I am monitoring scroll position but this method becomes unreliable on larger screens due to varying scroll positions. I need the navbar to beco ...

Sending data to API using AngularJS Http Post

Upon clicking "Add new User", a modal pop-up will appear with a form containing a text field and a checkbox. However, upon clicking the create button, the data is not being posted to the API and the modal pop-up remains open without closing. I would like ...

Web server experiencing issues with loading scripts and CSS files

After successfully building my project using CodeIgniter on localhost, I encountered an issue when trying to run it on a webhost. The site was functional but the design elements such as scripts and stylesheets were not loading properly. Before uploading t ...

Positioning a div with text over an image in a way that it

Hey everyone, I've run into a bit of an issue with my project. I'm trying to create a system where text appears over an image, but the problem is that my div is set to absolute position and I can't switch it to relative without causing major ...

The error message "Your session has expired" is displayed by the Wysiwyg

The WysiwygPro editor displays a dialog error message stating, "Your editing session has expired. This is usually caused by a long period of inactivity. Please re-load the page," when clicking on any controls such as Image, Media, Emoticon, etc. This iss ...

Tips for inserting the <style> element within a Vue.js component

Currently working with Vue.js v2, I am facing an issue where I have a CSS stylesheet stored as a string in a variable. import sitePackCss from '!!raw-loader!sass-loader!../../app/javascript/styles/site.sass'; I am trying to generate a <style& ...