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

What is the method for adjusting the position of materialize CSS select options?

https://i.stack.imgur.com/b9p9T.png One issue arises when I open the Materialize CSS select, as the options end up covering the input. Ideally, I prefer the options to appear underneath the input. <div class="input-field "> ...

What is the best way to utilize $(target) within a directive?

I created a custom directive for selecting time using two blocks. The challenge is detecting the target event on specific blocks within the directive's template. Directive Template: <div class='time-picker-container'> <div clas ...

The web server is unaware of the CSS and JS references

After loading my ASP.NET MVC project on the web server, I encountered an issue where none of my CSS and JS references were loaded. Some of the references in my default layout are listed below: <head> <link href="/Scripts/css/bootstrap ...

Unchecking and checking the radio button is necessary in order for it to function properly

Today, I'm puzzled by the odd behavior of my radio buttons in a pixel drawer project. In order for the radio button to function properly, I have to uncheck it and then recheck it. The pixel drawer allows me to change colors and sizes using these radio ...

Tips for delivering a variable to a React Native Stylesheet

Is there a way to pass a variable to the "shadowColor" property in my stylesheet from an array declared in the code above? I keep encountering a "Can't find name" error. Attempting to use a template literal has not resolved the issue. Any assistance w ...

Troubleshooting the sidebar pin-unpin problem using Jquery and CSS

I have created a single side panel that allows me to toggle between opening and closing the sidebar by hovering on it. I can also pin and unpin the sidebar by clicking on the pin image. Now, I want to open the sidebar onClick instead of onHover and remove ...

Utilize jQuery and JavaScript dynamically in an HTML document on iOS devices

Having some trouble with this code snippet and getting it to work as intended. - (void)viewDidLoad { [super viewDidLoad]; _webview.delegate = self; [_webview loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBun ...

Samsung Galaxy S7 can interpret alphabetical parameters as numbers in a link sent via SMS

When trying to open a text message with a new message on my website using a link, I encountered an issue specifically with the Galaxy S7. The following code works on most Android phones: sms:5555555555?body=JOIN However, on the Galaxy S7, the "?body=JOIN ...

Tips on formatting vueJS HTML5 with tidy without compromising its structure or content

Using the tidy tool on this VueJS code causes it to completely break: Here is the initial VueJS HTML code: $ cat sample_vue.html ... <tbody> <tr v-for="task in tasks"> <td><strong>{{task.title}}< ...

What is the best way to extract text using Selenium in Java?

My goal is to extract the text $1.00 from the HTML code snippet below (I already have the xpath, so no need to worry about that). Let's assume the xpath is //*[@id="price-string"] <strong id="price-string">$1.00</strong> ...

Inconsistency with Mobile Viewport Problem

Apologies for the chaos below, but I've spent quite some time attempting to fix this on my own. It's time to surrender and seek assistance! Here are some screenshots to illustrate the issue: The problem is that sometimes the webpage functions c ...

Changing CSS attributes with jQuery when conditions are met

After creating menus with expandable items that change style upon clicking, I encountered an issue where the styling changes were not being applied correctly. To address this problem, I followed Sushanth's suggestion and replaced $this with $(this), ...

Updating the input value of one field by typing into another field is not functioning properly when trying to do so for

I'm managing a website with a form that has three fields which can be duplicated on click. Here is an excerpt of my code: $(document).ready(function() { var max_fields = 10; var wrapper = $(".container1"); var add_button = $("#niy"); var ...

Is there a way to configure the text box to allow for range values input?

Is there a way to create an input box that only accepts values between 20 and 40? I want to restrict single numbers within that range. How can I define the range for this specific input box? If anyone can help me achieve this, it would be greatly apprecia ...

What is the best way to format a time in a 12-hour clock using JavaScript?

Is it possible to create a timer that performs an action after 12 hours? I want the timer to start at 6am and end at 6pm, lasting for exactly 12 hours. Additionally, I'm interested in converting my current 12-hour clock into a 24-hour format. I am se ...

Press the div, excluding the button - Vue

I have a basic div that spans 100% of the width, containing a button inside. The issue I'm facing is that when I add a click event to the div, the entire div becomes clickable (including the button within it). What I want is for the whole div to be ...

Material-UI's simplification of 10px comprehension

I'm a bit confused about why we have to do this for the 10px simplification: html { font-size: 62.5%; /* 62.5% of 16px = 10px */ } Shouldn't the following code handle everything? const theme = createMuiTheme({ typography: { // Set the ...

What measures can be taken to safeguard this hyperlink?

Is there a way to conceal HTML code from the source code? For instance: jwplayer("mediaplayer").setup({ file: "http://example.com/Media.m3u8", autostart: 'true', controlbar: 'bottom', file: "http://exa ...

What is the best way to enable an image to be moved on top of another image?

Is there a way to allow users to drag around an image that is positioned on top of another image in an HTML file? I want the superimposed image to stay within the boundaries of the underlying image. Any suggestions on how this can be achieved? <html& ...

The issue of transform scale not functioning properly in conjunction with background clip and gradients in CSS

Looking to transform a div with the transform: scale(-1,1) property while using background-clip: text on the text within it. However, this causes the text to disappear. Here's what I've attempted: .reverse { transform: scale(-1, 1); } .gr ...