Creating a scrollable div with a fixed background using HTML

Attempting to create a full-screen image background with a scrollable div in its center, I crafted the following code:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Bio</title>
<link href="../css/layout-base.css" rel="stylesheet">
<script type="text/javascript" src="../jquery/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
    $(window).ready(function(){
        var background = $('#background');
        var scrollable = $('#scrollable-container');
        var halfWhite = $('#halfWhite');
        var halfBlack = $('#halfBlack');
        var maxWidth = $(window).width();
        var maxHeight = $(window).height();

        background.css("height",maxHeight);
        background.css("width",maxWidth);

        scrollable.css("height",maxHeight);

        halfWhite.css("height",maxHeight);
        halfWhite.css("width",maxWidth/2);
        halfBlack.css("height",maxHeight);
        halfBlack.css("width",maxWidth/2);
    });

    $(window).resize(function(){
        var background = $('#background');
        var scrollable = $('#scrollable-container');
        var halfWhite = $('#halfWhite');
        var halfBlack = $('#halfBlack');
        var maxWidth = $(window).width();
        var maxHeight = $(window).height();

        background.css("height",maxHeight);
        background.css("width",maxWidth);

        scrollable.css("height",maxHeight);

        halfWhite.css("height",maxHeight);
        halfWhite.css("width",maxWidth/2);
        halfBlack.css("height",maxHeight);
        halfBlack.css("width",maxWidth/2);
    });
</script>
</head>
<body>
<div id="background">
    <div id="halfWhite"></div>
    <div id="halfBlack"></div>
    <div id="scrollable-container">
        <div class="content">
            <div id="text"></div>
            <a href="#" class="menu" id="home" target="_self"><img src="../media/index/tasto1.png"/></a>
            <a href="#" class="menu" id="events" target="_self"><img src="../media/index/tasto2.png"/></a>
            <a href="#" class="menu" id="gallery" target="_self"><img src="../media/index/tasto3.png"/></a>
            <a href="#" class="menu" id="disco" target="_self"><img src="../media/index/tasto4.png"/></a>
        </div>
    </div>
</div>
</body>
</html>

Utilizing the appropriate CSS:

body{
overflow:hidden;
margin:0!important;
}
#background{
background-image:url(../media/index/back.png);
background-size:contain;
background-position:center;
background-repeat:no-repeat;
}
 #halfWhite{
position:relative;
background-color: white;
z-index: -10;
float: left;
}
#halfBlack{
position:relative;
background-color: black;
z-index: -10;
float: right;
}
#scrollable-container{margin-left: 15%;margin-right: 15%;background-    color:rgba(0,0,0,0.00);}
.content{
height:98%;
position: relative;
top:1%;
padding-left: 15%;
padding-right: 15%;
box-shadow: -10px 2px 15px #dedede,10px -2px  15px #dedede;
-moz-box-shadow:-10px 2px 15px #dedede,10px -2px  15px #dedede;
-webkit-box-shadow:-10px 2px 15px #dedede,10px -2px  15px #dedede;
background-color:rgba(255,255,255,0.8);
}
#text{position:absolute;top:10%;width:100%;height:100000px;width:70%}
.menu{
width:15%;
-webkit-transition: all 0.4s linear;
-moz-transition: all 0.4s linear;
-o-transition: all 0.4s linear;
-ms-transition: all 0.4s linear;
transition: all 0.4s linear;
}
.menu:hover{
-webkit-transform: scale(0.85,0.85);
-moz-transform: scale(0.85,0.85);
-o-transform: scale(0.85,0.85);
-ms-transform: scale(0.85,0.85);
transform: scale(0.85,0.85);
}
.menu img{width:100%}
#home{position:absolute;top:0px;left:0px;}
#events{position:absolute;top:0px;right:0px;}
#gallery{position:absolute;bottom:0px;left:0px;}
#disco{position:absolute;bottom:0px;right:0px;}

Desiring the #text div to scroll while maintaining the background fixed, I've encountered issues. How can I achieve this layout effectively?

Answer ā„–1

Ensure that only the #text within this div has a style="position:fixed", while the other parts maintain position:absolute.

Answer ā„–2

To ensure your background stays in place, set it as a fixed position in your HTML code. The rest of your content should then be layered on top without the fixed positioning.

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

Press the Enter key to generate a new table row

I have been dynamically creating an HTML table. Each row contains two columns created through a recursive call. Currently, a new row is generated by clicking on the second cell, but I want to switch this action to the "Enter" key press. Although my code su ...

Find the correct file path for input using JavaScript or Angular 2

How can I retrieve the full file path of a selected Excel file using either pure JavaScript or Angular 2? I am looking to have the user select an Excel file, which will then be sent to a C# WEB API controller for further processing. Currently, my setup is ...

Is it possible to simultaneously send a JSON object and render a template using NodeJS and AngularJS?

I'm currently facing issues with my API setup using NodeJS, ExpressJS Routing, and AngularJS. My goal is to render a template (ejs) while also sending a JSON object simultaneously. In the index.js file within my routes folder, I have the following s ...

On-page refresh triggering HTTP 404 error in Vue3 routing situation

Issue Upon reloading a route, such as /installer, in Vue3.js, I encounter the following error: https://i.sstatic.net/UKxdk.png Code Snippet I am utilizing the Router with the setup below: const router = createRouter({ history: createWebHistory(proces ...

Turn off scrolling but allow dragging on iPhone

Is it possible to disable scrolling but still allow dragging on the <canvas> element in iPhone? Currently, when you drag the <canvas>, the entire page also scrolls, which is not the desired behavior. <meta name="viewport" content="wid ...

Unable to alter state from the onClick event of a dialog button

In the process of developing a Next.js app, I encountered an interesting challenge within one of the components involving a DropdownMenu that triggers a DialogAlert (both powered by Shadcn components). The issue arises when attempting to manage the dialog& ...

Encountered an issue retrieving two rows nested within a parent row using Bootstrap 4 and VueJs

Currently, I am working on a VueJs and Bootstrap4 component where my aim is to achieve a design similar to the one shown using the available bootstrap classes. After going through the documentation, I came across the customized classes h-75 and h-25 provi ...

Is it possible to convert ejs to jade?

I'm struggling with the conversion of this ejs code to jade: <h1>Iā€™m planning on counting up to <%= counter %></h1> <p><% for(var i = 1 ; i <= counter ; i++) { %> <%= i %>... <% } %></ ...

Stop scrolling on the body of the webpage

I am struggling to find a solution to completely disable scrolling on the HTML body. I have experimented with different options, but none seem to work as desired: overflow: hidden; did not disable scrolling, only hid the scrollbar. position: fixed; w ...

Unexpected issue with PHP/Ajax/JQuery response functionality

I am experiencing an issue with my index.php file. Here is the code: <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script> <script src="ajax.js"></script ...

In search of javascript implementations of the pubhubsubbub protocol that are open source

Can you list out some of the open-source Javascript implementations for the PubSubHubbub protocol, starting with the publishing side? ...

I'm having trouble understanding why my data does not appear even though there is space allocated for it automatically

I'm facing an issue with my code that is supposed to populate a table with dynamic content using react and ant.design. Everything seems to be working fine, but the actual content is not displaying - only the space for it is created. What's happe ...

Tips for adjusting the size of a container to fit its child element in a flexbox layout, where the flex-direction is set to column

Below is the functional code: .container{ display: flex; background-color: lightgreen; justify-content: center; alighn-item: center; } .child{ margin-left: 10px; height: 200px; background-color: yellow; display: flex; flex-direction: ...

Is it possible to search for a date within a string using jQuery?

Here's a unique challenge I'm facing with my to-do list app - users can quickly add tasks without filling out a detailed form. The catch? I need to find dates in their text entries, which are typically in YYYY-MM-DD format. For instance, if they ...

The text in my image is positioned away from the top

Hi there, I am new to exploring HTML and CSS and I have been trying to display some images and text on a webpage. My goal was to have the text appear next to the image, which is working fine. However, I am encountering an issue where the text aligns itself ...

jQuery: Issue Encountered with POST Request when Offline (iOS & Chrome)

After developing an HTML5 web application with offline capabilities using AppCache, the process flow is as follows: Online: While connected to the network, the app loads base information in advance. Offline: Users can take the app offline on their tablet ...

The appearance of the page varies between Ubuntu and Windows 7 when viewed on Firefox 31

This situation is completely new to me: The page I designed appears differently on Firefox 31 in Ubuntu (correct): compared to Windows 7 (wrong): I was able to replicate this issue on another Windows 7 machine using FF 31. My HTML and CSS both validate w ...

Resolving the Table Issue with 'onclick' in Javascript

Apologies for the lack of creativity in the title, I struggled to come up with something fitting. Currently, I am engaged in the development of a user-friendly WYSIWYG site builder. However, I have encountered an obstacle along the way. I've devised ...

On my webpage, there are two buttons labeled "Save" and "Complete". I am in need of creating two distinct alerts for each of the input fields

If the user does not enter a value in the input box for charge_amt, I have set up an onbeforeunload jQuery event to notify them. Once they enter the amount, they will be able to save. <td><input type="hidden" name="charge_cc" value="0" class=""&g ...

searchkit - Issue with Maintaining State of RefinementListFilter Checkboxes

I was curious about the functionality of the RefinementListFilter in searchkit. I have multiple filters that are boolean values, such as {field: 'hasChildren': {'1' : 'Yes', '0': 'No'}} to illustrate the tr ...