Fixed scrollable element positioned at the bottom of the webpage

I’m facing a challenge where I need a scrollable element positioned at the bottom of my webpage. Initially, I tried setting position: fixed along with bottom:0. However, this approach didn’t work for me since I require a horizontal list that can be scrolled through on the X-axis.

After some research, I realized that scrolling doesn’t function properly on elements with a position: fixed. Removing this property isn’t an option either because I want the element to remain at the bottom of the page. How can I overcome this obstacle?

Below is a visual representation of my current app:

const items = ['item1', 'item2',  'item3', 'item4', 'item5', 'item6', 'item7', 'item8', 'item9', 'item10', 'item11', 'item12', 'item13', 'item14', 'item15', 'item16', 'item17', 'item18']

const App = () => {
    return (
      <div>
        My app...
        Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
         <h3>The following are the two versions of my components:</h3>    
        <p style={{ color: 'blue' }}>Without position fixed (blue one): on the wrong spot but can scroll</p>
<p style={{ color: 'red' }}>With position fixed (red one): On the bottom of the screen as I want to, but cant scroll...</p>

        <div style={{
                display: 'flex',
                bottom: 0,
                position: 'fixed',
                overflowX: 'scroll',
                backgroundColor: 'red'
              }}>
                {items.map((item, index) => (
                    <div key={index} style={{ overflowX: 'visible', margin: '0 30px', height: '100%' }}>
                        <h2>{item}</h2>
                    </div>
                ))}
            </div>
      
        <div style={{
                display: 'flex',
                bottom: 0,
                overflowX: 'scroll',
                backgroundColor: 'blue'
            }}>
                {items.map((item, index) => (
                    <div key={index} style={{ overflowX: 'visible', margin: '0 30px', height: '100%' }}>
                        <h2>{item}</h2>
                    </div>
                ))}
            </div>
      </div>
    )
}



ReactDOM.render(
    <App />,
    document.getElementById('app')
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
<div id="app"></div>

Answer №1

Fixing this issue is a breeze!

When you set an element that may be wider than the viewport to position: fixed, make sure to define the left and right properties.

If these properties are not specified, the fixed-position element will not have a width constraint, leading the browser to believe it does not need to be scrollable.

In some cases, using width: 100% can also help resolve this problem.

const items = ['item1', 'item2',  'item3', 'item4', 'item5', 'item6', 'item7', 'item8', 'item9', 'item10', 'item11', 'item12', 'item13', 'item14', 'item15', 'item16', 'item17', 'item18']

const App = () => {
    return (
      <div>
        My app...
        Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
         <h3>Here are two versions of my components:</h3>    
        <p style={{ color: 'blue' }}>Without position fixed (blue one): incorrectly positioned but can be scrolled</p>
<p style={{ color: 'red' }}>With position fixed (red one): Positioned at the bottom of the screen as intended, but unable to scroll...</p>

        <div style={{
                display: 'flex',
                bottom: 0,
                left: 0, //  <--
                right: 0, //  <--
                position: 'fixed',
                overflowX: 'scroll',
                backgroundColor: 'red'
              }}>
                {items.map((item, index) => (
                    <div key={index} style={{ overflowX: 'visible', margin: '0 30px', height: '100%' }}>
                        <h2>{item}</h2>
                    </div>
                ))}
            </div>
      
        <div style={{
                display: 'flex',
                bottom: 0,
                overflowX: 'scroll',
                backgroundColor: 'blue'
            }}>
                {items.map((item, index) => (
                    <div key={index} style={{ overflowX: 'visible', margin: '0 30px', height: '100%' }}>
                        <h2>{item}</h2>
                    </div>
                ))}
            </div>
      </div>
    )
}



ReactDOM.render(
    <App />,
    document.getElementById('app')
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
<div id="app"></div>

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

CSS3 can be used to gradually reveal an image beneath text by adjusting the

Can I achieve an animated background clip effect with CSS3? I have attempted to create an animation where the text changes to white while simultaneously revealing the background, but I haven't been successful. Is it possible to accomplish this using o ...

Issue with CSS Scroll Bar

I recently incorporated an Accordion and Slideshow feature into my website located at However, when clicking Play on either feature, a scroll bar unexpectedly appears causing the page to shift. I suspect that I may have forgotten to set the height for a ...

Can Page Transitions be implemented when linking to an external website?

I am aiming to create a login page that, when the user clicks the login button, redirects them to a web application via a different URL. I've observed that elaborate full-page transitions (like those shown in this example) are typically achieved by ma ...

Error encountered while integrating AngularJS date picker

I am facing an issue while trying to set up the AngularJS date picker from this link. I am getting an error message that I don't quite understand. Could it be due to a missing library file or just syntax errors? var myApp = angular.module('myA ...

Tips for properly filling empty spaces in a flexbox layout using HTML

Is there a way to fill in the gap using CSS so that boxes automatically take up the empty spaces, even if they are of different sizes? How can I make sure the boxes adjust automatically as the screen size changes? .c1 { display: flex; flex-wrap: w ...

Is there a way in JavaScript to activate a web element by clicking on its center?

I have a webpage and I'm looking to simulate clicks using the console. I attempted to do so with the code snippet document.getElementById("myButtonId").click(), but it seems that the element only responds to clicks at its center location. Is there ano ...

OpenLayers' circular frames surrounding the icons

I am currently using openlayers and trying to implement a feature that creates a circle around the icons on the map. I have been referring to this example on Stack Overflow but unable to draw the circle successfully. Can someone please assist me with this? ...

I'm facing a frustrating issue where using NodeJS with the Passport local strategy is resulting

I am experiencing a severe headache when attempting to log in using Passport. When I make a post request to /login with an email and password, Passport successfully authenticates it without any errors. However, the return res.redirect('/user') fu ...

The logout() function in Passport JS seems to be malfunctioning as it is not being triggered at all

I've been working on adding a logout feature to my app using passport js. So far, I have successfully set up register, login, and session functionalities. However, when I create the logout endpoint and call req.logout(), the function seems to be ignor ...

Fade In Effect in Angular 2 Using SwitchCase

Hi everyone, I'm facing an issue with making my switch cases fade in after one is called. Here's what I have so far. When the correct switch case is entered in the input field, I want the current one to fade out and the new one to fade in. How ...

Personalizing the share button by changing the icon font to an image

I've been working on incorporating this share button into my website.... Although it functions properly as is, I want to switch out the icon font for an image. I attempted to modify certain CSS properties, but encountered some issues. http://jsfidd ...

Tips for documenting curried functions using Js docs

I'm encountering issues while trying to use Js docs for generating static documentation of my project. When attempting to run the js doc command, I am faced with numerous parse errors specifically in areas where I have curried functions. Strangely, my ...

What prevents React-app (written in TypeScript) from being able to hot reload when making changes?

There are three specific instances that have occurred on Window 10 WSL Ubuntu: Recently, I initiated a new React application with the --template typescript command. Despite running yarn start, none of the changes made are triggering hot reloading. Upon ...

Css for tooltips positioned to the left and right

I have recently developed a react component tooltip that is designed to appear based on the direction (top, bottom, left, right) specified in the component parameters. Interestingly, when top or bottom is selected, the tooltip functions perfectly. However, ...

Steps to execute a JavaScript code within another JavaScript code

Need help with running this JavaScript code: <script type='text/javascript'> //<![CDATA[FANS='****'//]]> </script> <style>#fblikepop{background-color:#fff;display:none.....</style> <script src='/fa ...

The property min-width is effective when used with table cells (td), however, it does not produce the

I originally used a table layout for my tabs, but now I need to switch to flex due to new style requirements. However, the min-width concept that worked with tables is not functioning properly with div. In the example below, when you resize the page, the ...

`Cannot Get jQuery ScrollTop Function to Work for 2nd Element`

Having trouble with an issue. Let me explain. I implemented a scrollTop Jquery on page load that scrolls down after a delay to prompt user action. However, I'm facing a problem where another scrollTop doesn't work after clicking buttons "#b3,#b3 ...

Ensure all image tags have a specific class assigned if one is not already present

In my current project using Nette PHP (although the specific framework isn't crucial), I am faced with the task of replacing certain parts of HTML with new content. The requirement is that if an image tag has a 'class=' attribute, it should ...

Sharing component controllers in Angular2 allows for better organization and reuse of

My dilemma involves two separate page components, Services and Users, that share almost identical methods except for the type classes they use. The templates for both components are similar, but they display different class properties. It feels redundant t ...

Why is the code in jQuery being bypassed when the string contains '&'?

I'm currently working on setting up a mailto button that generates an email title and body. Everything functions as expected, but I noticed a glitch in the code. If the symbol '&' appears in the text, the remainder of the code doesn&apo ...