Creating a scrollable HTML5 div container with fixed divs positioned within it

I am attempting to develop an app container that mimics the functionality of Microsoft Excel. The container should scroll both horizontally and vertically, with fixed headers on the left and top that move along with the content. Here is a rough representation:

+---ScrollableContainer---------+
|+-a-++----b--------------------|-------------------+
||   ||                         |                   |
||   |+-------------------------|-------------------|
||   |+----Content--------------|-------------------+
||   ||                         |                   |
||   ||                         |                   |
+-------------------------------+                   |
 |   ||                                             | 
 |   ||                                             |
 +---++---------------------------------------------+

The ScrollableContainer serves as the main container, offering horizontal and vertical scrolling capabilities.

Within the ScrollableContainer are 3 divs: a, b, and Content. The challenge I am facing is ensuring that the div a remains fixed on the left side while scrolling up and down, and that the div b stays fixed on top while scrolling left and right with ScrollableContainer. The Content div should be free to scroll in any direction. Think of it like an "Agenda". The a div represents the "HOUR" pivot, the b div represents the "DAY" pivot, and the Content acts as the agenda, organized by hours and days. The pivots should move along with the scroll.

EDIT:

Here is a partially functional example: - AndyM

.rows {
    height:200px;
    width:400px;
    background-color:rgb(240,240,240);
    position:relative;
}
.rows > header {
    position:absolute;
    top:0;
    left:0;
    bottom:0;
    width:40px;
    background-color:blue;
}
.rows > article {
    position:absolute;
    top:0;
    left:40px;
    bottom:0;
    right:0;
    overflow-x:scroll;    
}
.cols {
    position:relative;
    height:100%;
}
.cols header {
    height:40px;
    position:absolute;
    top:0;
    left:0;
    background-color:green;
}
.cols article {
    position:absolute;
    top:40px;
    bottom:0;
    left:0;
    overflow-y:scroll;
}

row {
    display:block;
    height:40px;
    white-space:nowrap;
}
cell {
    display:inline-block;
    height:100%;
    width:70px;
}
<section class="rows">
    <header>
        <row>
            <cell>Text</cell>
        </row>
        <row>
            <cell>Text</cell>
        </row>
        <row>
            <cell>Text</cell>
        </row>
        <row>
            <cell>Text</cell>
        </row>
        <row>
            <cell>Text</cell>
        </row>
        <row>
            <cell>Text</cell>
        </row>
    </header>
    <article>
        <section class="cols">
            <header>
                <row>
                    <cell>Text</cell>
                    <cell>Text</cell>
                    <cell>Text</cell>
                    <cell>Text</cell>
                    <cell>Text</cell>
                    <cell>Text</cell>
                    <cell>Text</cell>
                </row>
            </header>
            <article>
                <row>
                    <cell>Text</cell>
                    <cell>Text</cell>
                    <cell>Text</cell>
                    <cell>Text</cell>
                    <cell>Text</cell>
                    <cell>Text</cell>
                    <cell>Text</cell>
                </row>
                <row>
                    <cell>Text</cell>
                    <cell>Text</cell>
                    <cell>Text</cell>
                    <cell>Text</cell>
                    <cell>Text</cell>
                    <cell>Text</cell>
                    <cell>Text</cell>
                </row>
                <row>
                    <cell>Text</cell>
                    <cell>Text</cell>
                    <cell>Text</cell>
                    <cell>Text</cell>
                    <cell>Text</cell>
                    <cell>Text</cell>
                    <cell>Text</cell>
                </row>
                <row>
                    <cell>Text</cell>
                    <cell>Text</cell>
                    <cell>Text</cell>
                    <cell>Text</cell>
                    <cell>Text</cell>
                    <cell>Text</cell>
                    <cell>Text</cell>
                </row>
                <row>
                    <cell>Text</cell>
                    <cell>Text</cell>
                    <cell>Text</cell>
                    <cell>Text</cell>
                    <cell>Text</cell>
                    <cell>Text</cell>
                    <cell>Text</cell>
                </row>
                <row>
                    <cell>Text</cell>
                    <cell>Text</cell>
                    <cell>Text</cell>
                    <cell>Text</cell>
                    <cell>Text</cell>
                    <cell>Text</cell>
                    <cell>Text</cell>
                </row>
            </article>
        </section>
    </article>
</section>

The issue with this setup is that the vertical scrollbar is not visible, and the .col header does not scroll properly. Nonetheless, this example should provide a glimpse of the desired outcome.

Answer №1

If you desire a scrolling effect like this, you have two options: utilizing an iframe or implementing customized scrolling using JavaScript. When using an iframe, you can simply fix the positions of divs 'a' and 'b', but there may be some complexities involved. On the other hand, with JavaScript, you can create a solution similar to the following:

var x=0, y=0;
ScrollableContainer.onwheel = function(e) {
  if(firefox) {
    x+=e.deltaX*16;
    y+=e.deltaY*16;
  } else {
    x+=e.deltaX;
    y+=e.deltaY;
  }
  a.style.marginTop = y + 'px';
  b.style.marginLeft = x + 'px';
  content.style.marginTop = y + 'px';
  content.style.marginLeft = y + 'px';
};

Although untested, in order for this code to function properly, divs 'a', 'b', and 'content' must each reside within their own container. However, you are free to arrange these containers to position your divs as needed.

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

An issue with JSPDF arises when used on mobile devices

Currently, I am working on a project to create a responsive web application, which involves utilizing JSPDF for generating PDF reports directly from HTML. For a demonstration of the functionality, you can check out this Demo. Unfortunately, when trying t ...

How to Align Paypal Button in the Middle of a Table Cell within a Concealed Form Using HTML and

Currently, I am in the process of developing a payment page that enables payments through Paypal using Instant Payment Notification. The initiation of this process involves sending a POST request to Paypal via a submit button along with multiple hidden for ...

Effortlessly retrieving the id attribute from an HTML tag using jQuery

Currently, I am encountering an issue with a code snippet that is designed to extract the value from an HTML tag. While it successfully retrieves a single word like 'desk', it fails when attempting to do so for an ID consisting of two or more wor ...

HTML5 full-screen API and its compatibility with different browsers

I'm curious to know the level of support for HTML5 full-screen API in popular browsers. Which is the earliest version of each browser that fully supports it? And for any browsers that don't (like IE I suppose), are there third-party libraries ava ...

Attempting to alter the background image through the action of clicking on an image using jQuery, HTML, and CSS

I have created custom weather icons like a sun, cloud, and rainy cloud using Photoshop. My goal is to allow users to click on these icons and change the background image of the website's body. However, despite my efforts, clicking on the images does n ...

Creating HTML forms allows for images to be used as checkboxes

I'm attempting to convert an HTML forms checkbox into a clickable image that changes its appearance when clicked. Additionally, I need it to be capable of storing one or two variables (specifically for generating them with row and column values) and f ...

Adjusting background size using jQuery as the window is resized

Exploring ways to dynamically resize the background image of my website based on the current window dimensions using jQuery. At the moment, I have tried the following approach: $(window).resize(function() { $("body").css({"background ...

What are the steps to overlay a button onto an image with CSS?

As a CSS newbie, I have a question that may seem silly or straightforward to some. I am struggling with placing a button over an image and need guidance on how to achieve this effect. Specifically, I want the button to appear like this blue "Kopit" button ...

What is the process for extracting specific text from a web page source using Python with Selenium?

The following is the HTML source code: <div class="dropdown-popup"> <a href="/integrations/sources/" class="dropdown-item">Sources</a> <a href="/integrations/destinations/" cla ...

Steps to make a sub Post or page on WordPress

Seeking to add sub posts within my website's main posts. The URL structure for the main post will be: site.com/post-title I envision sub posts following this format: site.com/post-title/subpost1 site.com/post-title/subpost2 site.com/post-title/ ...

Looking for a PHP add-on for fpdf converter that can handle ul li tags

I need assistance with using fpdf to convert dynamic site content to pdf. The issue is that fpdf does not support ul li tags. Is there an add-on available for fpdf that supports ul li and ol li tags in html? To provide more context: The content being con ...

I'm currently in the process of incorporating horizontal scrolling into various sections of an image gallery. The images will stack vertically only when the window width

I am currently developing an image gallery with multiple sections that contain various images. My goal is to arrange each section of images in a single row, allowing horizontal scrolling similar to Netflix's layout. However, I'm facing challenges ...

Tips for making a standout testimonial card?

Apologies for the simplistic inquiry. As a fresh student of a full stack web developer bootcamp, I find myself grappling with this particular challenge. How can I go about creating a testimonial card similar to this one? I've attempted to write code ...

Enhancing imported models in Three.js with antialiasing

When I import an OBJ model into my scene, it appears jagged and lacks smoothness. This is puzzling to me because when opened in Blender, the model looks perfectly smooth. On the other hand, the built-in geometries such as new THREE.SphereGeometry(4, 20, 2 ...

The order of CSS precedence shifts even when the class sequence is the same

In my development setup, I have a react component that is embedded within two distinct applications each with their own webpack configurations. Within the component, I am utilizing a FontAwesome icon using the react-fontawesome library: <FontAwesom ...

A guide to efficiently filling multiple rows of images with different heights while preserving their aspect ratio

I am facing a design challenge that I believe can be solved using CSS, although it might require some Javascript. My issue involves a gallery of images with varying sizes and proportions. I would like to achieve the following: Distribute the images in m ...

Why isn't the virtual directory in IIS 7 pointing to the root website?

I need to set up a virtual directory in IIS 7 that will point to the root of a website on our server. Here is an example of the structure: Websites: | --- AssetsServer | - /images/ | - /css/ | - etc. | --- demoserver ...

The printing function for the window system can cause disruptions to the layout of the table

After creating a page with a simple table that can be filled in and printed, I noticed some issues with the table formatting after printing. The intended table design was supposed to look like this: https://i.stack.imgur.com/aAk89.png However, upon print ...

What is the best way to utilize Enquire.js for dynamically adding and removing CSS classes?

I'm looking to dynamically add and remove a css class based on a media query using Enquire.js but I could use some guidance on utilizing the functions properly. Here's what I envision in pseudo code: if (screens max-width > 480px){ #thumb.r ...

Resetting the "clear: both" property for the nth-child element when multiple nth-child elements are being inherited

Currently utilizing CSS (specifically SCSS) to style the same element on various media sizes - A, B, and C. Utilizing the following for A: &:nth-of-type(2n+1) { clear: both; } For B: &:nth-of-type(3n+1) { clear: both; } Finally, for C: ...