Display elements that are positioned absolutely within a container with scrolling overflow

My modal contains a scrollable list with many items that have absolute positioned elements causing overflow within the modal.

How can I ensure that the absolute positioned elements are visible in this scenario?

.modal {
  width: 300px;
  border: 1px solid red;
  margin: 0 auto;
}

.list {
  width: 100%;
  max-height: 500px;
  margin: 0;
  padding: 0;
  overflow-y: scroll;
}

.content {
  list-style: none;
  height: 200px;
  border: 1px solid rgb(46, 20, 20);
  position: relative;
}

.overflow {
  position: absolute;
  left: -50px;
  top: 25%;
  border: 1px solid green;
  height: 100px;
  width: 100px;
}
<div class="modal">
  <ul class="list">
    <li class="content">
      Content area
      <div class="overflow">overflow</div>
    </li>
    <li class="content">
      Content area
      <div class="overflow">overflow</div>
    </li>
    <li class="content">
      Content area
      <div class="overflow">overflow</div>
    </li>
    <li class="content">
      Content area
      <div class="overflow">overflow</div>
    </li>
  </ul>
</div>

Answer №1

It may seem that setting overflow-x: visible on the .list element would solve the issue.
However, CSS actually defaults to hiding the other overflow property (overflow-y) if one is set to hidden or scroll.

To make absolute positioned elements visible again, you will need to wrap another container around your .list.
In this example, I used the .modal, changed it to scroll, added a max-height, and removed both from the .list. Additionally, I made the modal 100% width and centered the list.

Now, when you scroll, it's the modal instead of the list, making your absolute positioned elements visible.

This isn't a direct solution to the problem, more of a workaround.

Note: If your absolute positioned elements extend beyond the modal, they will disappear again. Keep that in mind.
Note2: If you prefer not to add scroll to the modal, you can insert another div container inside the modal to wrap the list element.

.modal {
  width: 100%;
  border: 1px solid red;
  margin: 0 auto;
  max-height: 200px;
  overflow-y: scroll;
}

.list {
  width: 300px;
  margin: 0;
  padding: 0;
  margin: 0 auto;
}

.content {
  list-style: none;
  height: 200px;
  border: 1px solid rgb(46, 20, 20);
  position: relative;
}

.overflow {
  position: absolute;
  left: -50px;
  top: 25%;
  border: 1px solid green;
  height: 100px;
  width: 100px;
}
<div class="modal">
  <ul class="list">
    <li class="content">
      Content area
      <div class="overflow">overflow</div>
    </li>
    <li class="content">
      Content area
      <div class="overflow">overflow</div>
    </li>
    <li class="content">
      Content area
      <div class="overflow">overflow</div>
    </li>
    <li class="content">
      Content area
      <div class="overflow">overflow</div>
    </li>
  </ul>
</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

Avoid activating jQuery functions based on certain screen widths for menu/navigation system

Recently, I've delved into the world of jQuery and attempted to create a simple menu system. The menu is designed to expand its submenu when hovering over the list item at screen widths larger than 480px, and to expand when clicking on the list item a ...

changing the value of a text input based on the selected option in a dropdown using ajax

I attempted to update the text input value with data from the database after selecting an option from the dropdown list. However, I encountered an issue where the data is not populating the text input field. <?php //Including the database configuration ...

What is the best way to send data to a child component in Angular, including components that can be

There are two components in my project: the parent component and the child component, each with their own unique markup. It is crucial for this example that the child component fetches its own data to render and not be provided by the parent. Currently, th ...

Having trouble getting the items to show up on the canvas

I have been struggling to implement JavaScript on a canvas in order to display mice in the holes using the mouse coordinates. Despite trying many different methods and spending close to a month on this project, I still can't seem to get it to work acr ...

Capture the item selected from the dropdown using ng-model to retrieve the name instead of the

I need help getting the name/text/html of the selected option in a dropdown using angular.js, rather than just its value. Currently, I have this setup which retrieves the value: Here is my HTML code snippet <select class="SelectCar" ng-model="Selected ...

Implementing specific CSS styles for images that exceed a certain size limit

Currently, I am facing a dilemma as I work on developing a basic iPhone website that serves as a port for my blog. The main issue I am encountering is the need to add a border around images above a specific size and center them in order for the blog to hav ...

Challenges with uploading files using jQuery

Click here to upload a file I'm trying to create a feature where users can choose an image and have it displayed in place of the "trees" image. Feeling stuck, I could really use some guidance. Check out the code below: <div class="user-editab ...

Align the elements of the contact form to the opposite sides

I am experiencing an issue with my contact form where all elements are flowing horizontally instead of vertically. I would like everything to be floated to the left and aligned vertically, except for the "message" box and submit button which should be on t ...

Integrate HTML parsing both inside and outside of an iframe using BeautifulSoup

My current project involves web scraping a real estate listing platform using Selenium, BS4, and Python. The script works by fetching the links to each listing page before proceeding to parse the HTML content of those pages. One key component is a Chrome E ...

Disable multiple buttons at once by clicking on them

What is the best way to disable all buttons in a menu when one of them is clicked? Here is my code: <div class="header-menu"> <button type="button"> <i class="fa fa-search" matTooltip="Filter"& ...

Flyer - Chart "dimmed" and unselectable when dimensions are specified as a proportion

I am currently working on displaying a map within a container. I have successfully been able to display the map by setting its size to a specified number of pixels. However, my goal is to have the height of the map adapt to the size of the container dynami ...

Alter the background color of a table cell in Angular HTML depending on a boolean value

Attempting to use Angular ng-class to set the background color of a table cell. I'm referencing code snippets from these resources: Angular: How to change the color of cell table if condition is true Change HTML table cell background color using ...

Creating a CSS circle spinner with a half moon shape is an innovative way to add a unique touch

Image: Circular spinner rotating along the border rim of other solid circle For more details, please visit: https://codepen.io/sadashivjp/pen/oqqzwg I have created a UI codepen here and welcome any modifications or solutions. The code snippet is provided ...

detect mouse click coordinates within an iframe that spans multiple domains

I am currently encountering an issue with tracking click position over a cross-domain iframe. Here is my current code: <div class="poin"> <iframe width="640" height="360" src="http://cross_domain" frameborder="0" allowfullscreen id="video">< ...

What are the style attributes that can be edited in each ant design component?

My goal is to customize an ant design card by adding a border only on the left and right sides of the card. The bordered attribute in the card component seems to either remove the entire border or display it on all sides. I am looking for a way to specif ...

Non-clickable image

My social media page icons are not hyperlinked, and I can't figure out why. I've surrounded them with the href attribute, but for some reason, it's not working. Can anyone provide assistance? Here is the HTML code: <!DOCTYPE html> ...

Using JavaScript values retrieved from a database to dynamically adjust the options in the second dropdown menu based on the selection made in the

I am currently working on a feature that involves populating two dropdown menus with values from a database. The idea is that when an option is selected in the first dropdown, the second dropdown should dynamically display relevant values based on that s ...

html div elements may not align correctly

Currently, I am in the process of coding a website that contains numerous images. To assist me in organizing and arranging these images, I have turned to angularjs. Initially, everything was progressing smoothly until this issue arose: The layout is stru ...

I am getting text content before the input element when I log the parent node. What is causing this issue with the childNodes

Does anyone know why 'text' is showing up as one of the childNodes when I console.log the parent's childNodes? Any tips on how to fix this issue? <div id="inputDiv"> <input type="text" id="name" placeholder="Enter the nam ...

The alert box fails to display in the correct orientation when the condition is activated

Currently, I am working on implementing a sign-up feature using PHP. My main goal is to successfully store the user-entered data in MySQL database while ensuring that no duplicate usernames are allowed during account creation. Although everything is functi ...