Fixed position buttons contained within a scrolling box

Having an overflow:scroll; box with lengthy content and two buttons as shown here.

My issue is that the buttons are not aligning properly at the end of the scroll box, you can see the problem here.

I've even created a fiddle to demonstrate the problem: https://jsfiddle.net/bananoga/70vy13ke/12/

This is my CSS code:

.scroll-div{
  border: 1px solid black;
  width:100%;
  height: 110px;
  overflow: scroll;
  contain: content;
  display: flex;
}

.inside-box{
    border: 1px solid black;
    width: 100px;
    min-width: 100px;
    height: 50px;
    margin: 10px;
}

.buttons{
   position: fixed; 
    left: auto;
    right: 19px;
    bottom: 5px;
    margin-top:5px;
}

Thank you for any help provided :)

Answer №1

The utilization of position: fixed on .buttons caused it to be removed from the regular flow of the document and positioned relative to the closest parent context. In this case, with contain: content applied to .scroll-div, it became the nearest context, thus positioning .buttons a fixed distance away from its boundaries. It's important to note that these boundaries refer to the outer container of .scroll-div, not its inner content.

When removing position: fixed along with associated styles, the buttons will display to the right of the last occurrence of .filter:

.scroll-div {
  border: 1px solid black;
  width: 100%;
  height: 110px;
  overflow: scroll;
  display: flex;
}

.filter {
  border: 1px solid black;
  width: 100px;
  min-width: 100px;
  height: 50px;
  margin: 10px;
}

.buttons {
  margin-top: 5px;
}
<div class="scroll-div">
  <div class="filter"></div>
  <div class="filter"></div>
  <div class="filter"></div>
  <div class="filter"></div>
  <div class="filter"></div>
  <div class="filter"></div>
  <div class="filter"></div>
  <div class="filter"></div>
  <div class="filter"></div>
  <div class="filter"></div>
  <div class="buttons">
    <button class="btn1">
    button1
    </button>
    <button class="btn2">
    button2
    </button>
  </div>
</div>


Edit

Considering the clarification provided in your comment:

body {
  margin: 0;
}

.container {
  max-width: 100%;
  overflow-x: auto;
  display: flex;
  padding: 20px;
  align-items: start;
}

.filter {
  border: 1px solid #333;
  padding: 20px;
  margin-right: 20px;
  min-width: 100px;
}

.filter:last-child {
  margin-right: 0;
}

.buttons {
  display: flex;
  margin-top: 10px;
}
<div class="container">
  <div class="filter">Filter Content</div>
  <div class="filter">Filter Content</div>
  <div class="filter">Filter Content</div>
  <div class="filter">Filter Content</div>
  <div class="filter">Filter Content</div>
  
  <!--
    This div will wrap both the last filter and
    the buttons below it to allow for the desired
    layout to be achieved without brittle hacks.
  -->
  <div>
    <div class="filter">
      Filter Content
    </div>
    <div class="buttons">
      <button>Button 1</button>
      <button>Button 2</button>
    </div>
  </div>
</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

What could be causing my animation element to not be aligned in the center?

I'm having trouble figuring out why the car in my animation isn't swerving around the middle line. It seems to be veering a bit off to the right? .car { width: 40px; height: 60px; background: #f00; left: 50%; transform: translate(-50 ...

Generating grid-style buttons dynamically using jQuery Mobile

I am in need of assistance to create a dynamic grid using jQuery Mobile. The grid should consist of buttons with either 'onclick' or 'href' functionality. The number of buttons should be generated dynamically at runtime. Specifically, I ...

Acquire the Information from a Textarea That Has Been Edited by the User

My challenge lies in taking user-entered text from a content editable textarea and sending it via POST request, but the fields edited by the user are returning with an empty textContent. The code snippet below shows that each .entryRow (obj) contains multi ...

The tale of a div's mysterious empty room

Once upon a time, in the world of HTML and CSS, there existed a lonely div. This lonely div longed for companionship, and one day, an inline img came to visit. They formed a bond and became good friends. But, no matter how hard the img tried, it couldn&apo ...

Is it possible to create a stylish CSS shadow effect?

As I work on converting a PSD design into HTML/CSS, I've encountered an intricate shadow effect created by the designer. I am struggling to replicate it using CSS. Is there a way to achieve this? If yes, then how can it be done? The shadow style is s ...

CSS: Using absolute and relative positioning within a parent element can result in elements overlapping

I want to create a box in html/css where the read more hyperlink text is positioned over the background image. The goal is to have additional text added to the description without overlapping the image. Here's an example of the current issue. Curren ...

Varied selection menu feature

Looking to build a new component: The idea is to create something similar to a dropdown list. I aim to incorporate this component into every cell (td) of table rows. The challenge lies in displaying the second div (item list) under the first div, but abov ...

Update the content of a div and refresh it when a key on the keyboard is pressed

I need to hide the images in a div when I press a key on the keyboard. How can I achieve this? <div> <span role="checkbox" aria-checked="true" tabindex="0"> <img src="checked.gif" role="presentation" alt="" /> ...

Website form phone number verification server

I am currently working on developing a website form where users can input their information, including their phone number. I am looking for a simple way to verify the user's phone number using PHP without the need for installation of SDKs or complex c ...

Listening to a sequence of mp3 tracks consecutively

I'm currently working on a project that involves playing a series of mp3 files consecutively. However, I've encountered an issue with my code snippet below: Here's the code snippet: function playAudio(){ var au = document.getElementById( ...

Tips for transferring data when clicking in Angular 5 from the parent component to the child component

I need assistance with passing data from a parent component to a child component in Angular 5. I want the child component to render as a separate page instead of within the parent's template. For example, let's say my child component is called & ...

Unexpected Facts about Refresh Flicker (Tumblr)

I've been attempting to implement a 'random background on refresh' feature for my Tumblr theme. As some may not be aware, Tumblr themes are comprised of HTML alongside embedded CSS and JavaScript. At the moment, I have been utilizing this p ...

Manually adjusting the aria-expanded attribute to "true" does not result in opening a new tab

After a certain condition is met, I want to open another tab. Below is my bootstrap navbar code along with the jQuery script. <ul class="nav navbar-default nav-justified" role="tablist" id="navbar"> <li role="presentation" class="active"><a ...

Is there a way to display the form values on the table once it has been submitted?

I'm struggling with my form input not showing up under the table headings after submission. I've reviewed the code multiple times, but can't figure out what's causing the issue. If you have any suggestions on how to write the code more ...

The ng-repeat directive in a row is malfunctioning

Just starting out with angularjs and facing an issue with getting data using ng-repeat within a div that is part of a row. I have implemented filtering and pagination from a dropdown, but it doesn't seem to be working as expected. Any assistance would ...

Hiding a parent DIV in JS based on specific content: Here's how

I need help figuring out how to hide multiple parent DIVs based on the content of a specific child DIV. Here's an example: <div class="report-per-day"> <div class="report-day">26 May 2022</div> <div class=" ...

PHP search function malfunctioning

I'm feeling quite confused about the current situation. I am utilizing a form that requires a student code input of "lz." <form action="classgrades.php?id=<?php echo $courseid ?>" method="post"> <input type="text" name="studen ...

Implement a JavaScript confirm dialog for a mailto hyperlink

Is there a way in javascript to automatically detect mailto links on the page and prompt a confirmation dialog when clicked by a user? I came across a method on this website for displaying an alert message. My knowledge of javascript is very basic. It&ap ...

What is the best way to place <a> links next to each other in the header?

Looking to align the links horizontally in the header using CSS, can someone assist me with this? <body> <nav> <div class="wrapper"> <a href="index.php"><img src="spaceship.png" alt="blogs logo& ...

Expandable tool tip box

I've specified the tooltip's width and height as 100% .tool-tip, .tool-tip.top{ width: 100%; height: 100%; margin-left: -43px; } However, it still fails to expand based on the content within. The issue can be seen here: http://jsfi ...