0

I'm trying to realize a Flex-layout with hidden scrollbars which I have realized. But now I also need a absolute/fixed button and I have failed to get it to work.

Without hidden scrollbars it works: enter image description here

But when I hide the scrollbars the button sticks to the top which is undesirable. enter image description here

<style>
    .root {
        background-color: #fff;
        display: flex;
        height:100%;
    }

    .pane {
        flex-grow: 1;
        flex-shrink: 1;
        display: flex;
        overflow-x: hidden;
        overflow-y: visible;
        -ms-overflow-style: none;
        height: 100%;
        width: 400px;
    }

    .pane::-webkit-scrollbar {
        display: none
    }

    div.pos {
        position: absolute;
        right: 0px;
        width: 32px;
        height: 32px;
        background-color: #01689B;
        color: #fff;
    }
</style>
<div class="root">
    <div class="pane">
        <div class="pos">x</div>
        <div style="height: 2000px">
            Lorem ipsum dolor sit amet, etc etc
            <br/> Lorem ipsum dolor sit amet, etc etc
            <br/> Lorem ipsum dolor sit amet, etc etc
            <br/> Lorem ipsum dolor sit amet, etc etc
            <br/> The button should stick to the right of the text and scroll width the text;
        </div>
    </div>
</div>
Ralf de Kleine
  • 11,464
  • 5
  • 45
  • 87

1 Answers1

1

The problem is simple, the absolute positioned element doesn't relate to the scrolling element.

Give it position: relative and it will.

Stack snippet

<style>
        html, body {
            overflow: hidden;
            height: 100%;
        }
        .root {
            background-color: #fff;
            display: flex;
            height: 100%;
        }
    
        .pane {
            position: relative;           /*  added  */
            flex-grow: 1;
            flex-shrink: 1;
            display: flex;
            overflow-x: hidden;
            overflow-y: visible;
            -ms-overflow-style: none;
            height: 100%;
        }
    
        .pane::-webkit-scrollbar {
            display: none
        }
    
        div.pos {
            position: absolute;
            right: 0px;
            width: 32px;
            height: 32px;
            background-color: #01689B;
            color: #fff;
        }
    </style>
    <div class="root">
        <div class="pane">
            <div class="pos">x</div>
            <div style="height: 2000px">
                Lorem ipsum dolor sit amet, etc etc
            </div>
        </div>
    </div>
Asons
  • 84,923
  • 12
  • 110
  • 165