overlapping an absolutely positioned div above a statically positioned div with unique overflow properties

I have a fixed div with a max-height, an overflow-y: auto and an overflow-x: hidden.

<div id="overlay">  <!-- position:fixed; -->

    <div class="close" >&times;</div> <!-- position:absolute; NOT WORKING -->

    <div id="overlay-content"> CONTENT HERE </div>
</div> 

<div id="mask"></div>  <!-- another position:fixed;  -->

I want to add a layer on top of my id="overlay" called class="close" and it's not going over.

If I put the following code

max-height: 50%;
height:auto !important;
overflow-y:auto;
overflow-x:hidden;

inside #overlay-content instead of inside #overlay then the (X) Circle appears on top, but the max-height and the overflow-y: auto doesn't work anymore...

JSFIDDLE: https://jsfiddle.net/g5Lt5oak/8/

You'll see the problem with the (x) circle not going over the FIX div. How can I fix this?

#mask { /* create are mask */
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0,0,0,0.6);
  z-index: 1;
  width: 100%;
  height: 100%;
  display: block;
}

#overlay { 
  width: 65%;
  margin: 0;
  padding: 10px;
  position: fixed;
  top: 10%;
  left: 17%;
  z-index: 2;
  display: block;
  background: white;
  max-height: 50%;
  height: auto !important;
  overflow-y: auto;
  overflow-x: hidden;
}

#overlay-content {
  /*  max-height: 50%;
  height: auto !important;
  overflow-y: auto;
  overflow-x: hidden;
  */
}

.close {
  display: block;
  position: absolute;
  top: -20px;
  right: -14px;
  background: #d1d1d1; /*#b1b1b1; */
  color: white;
  height: 45px;
  width: 45px;
  line-height: 45px;
  font-size: 40px;
  text-decoration: none;
  text-align: center;
  font-weight: bold;
  -webkit-border-radius: 40px;
  -moz-border-radius: 40px;
  -o-border-radius: 40px;
  border-radius: 40px;
  z-index: 10;
}

.close: hover {
  cursor: pointer;
  cursor: hand;
}
<div id="overlay">
  <div class="close">&times;</div>
  <div id="overlay-content">
    <br><img src="http://media02.hongkiat.com/ww-flower-wallpapers/roundflower.jpg"><br><br>
    <br><img src="http://media02.hongkiat.com/ww-flower-wallpapers/roundflower.jpg"><br><br>
    <br><img src="http://media02.hongkiat.com/ww-flower-wallpapers/roundflower.jpg"><br><br>
  </div>
</div>
<div id="mask"></div>

Answer №1

To fix this issue, simply enclose the absolute position div with a relative position div. Additionally, ensure that the width of the images within the overlay content is set to 100% and remove the initial line break tag.

<style>
.overlay-content img{
width:100%;
}
</style>
<div id="overlay">
<div style="position:relative">
<div class="close">×</div>
<div id="overlay-content">      
<img src="http://media02.hongkiat.com/ww-flower-wallpapers/roundflower.jpg"><br><br>
<br><img src="http://media02.hongkiat.com/ww-flower-wallpapers/roundflower.jpg"><br><br>
<br><img src="http://media02.hongkiat.com/ww-flower-wallpapers/roundflower.jpg"><br><br>
</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

Tired of the premium content on Medium.com. How can I conceal premium posts that are aimed at a specific class within a parent element?

I have noticed that all Premium posts contain an element with the class ="svgIcon-use" <svg class="svgIcon-use" width="15" height="15" viewBox="0 0 15 15" style=""><path d="M7.438 2.324c.034-.099.090 123 0l1.2 3.53a.29.29 0 0 0 .26.19h3.884c.11 0 ...

What is a creative way to design a mat-radio-group without traditional radio buttons?

I am looking to create a component that offers users a list of selections with the ability to make only one choice at a time. The mat-radio-group functionality seems to be the best fit for this, but I prefer not to display the actual radio button next to t ...

What are the steps to add a Search Box to my HTML Website?

Currently, I am in search of a way to incorporate a "Search" feature on my website that is built solely with HTML. I have added a Search box for the users but I'm uncertain about how to proceed next. Can I use PHP to enable the Search functionality o ...

What is the best way to insert two rows directly in the middle of two Bootstrap columns?

I need to align two rows in a straight line. Similar to the example shown in the image below: https://i.sstatic.net/EwRat.png After that, I want to split the Bootstrap into two columns, one with col-md-8 and the other with col-md-4. In the col-md-8 col ...

Error message: "An issue occurred with the Bootstrap Modal in

I've designed an AngularJS app like so: <!DOCTYPE html> <html ng-app="StudentProgram"> <head> <title>Manage Student Programs</title> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2. ...

What is the best way to display the tabcontent when clicking on a menu tab in this code, as neither method seems to work?

Take a look at my JSFiddle demo: <http://jsfiddle.net/xrtk9enc/2/> I suspect that the issue lies within the javascript section. My html code includes an Unordered List that serves as the tab menu. Each href of the menu corresponds to a tab content, ...

Navigating through the img src using JavaScript

Currently, I am working on a task that involves the following code snippet: <input type="file" id="uploadImage" name="image" /> <input type="submit" id="ImageName" name="submit" value="Submit"> My goal is to have the path of the selected imag ...

Add a fading transition feature to images that are loaded at a later time

I used a clever technique to create a blur effect by loading a small, lightweight image first. Once the main background image is loaded, it swaps out the 'data-src' with the actual image. However, I am facing an issue with the abrupt transition, ...

Display sliding content when the page is loaded

I want to implement a unique feature on my webpage where a fixed div initially appears fully visible and then slides away after a few seconds, revealing its normal mouseover functionality. The challenge is to achieve this effect using CSS or JavaScript if ...

What is the best way to ensure that navigation takes up the full width of the screen in pixels when

Trying to use jQuery to set a specific pixel width for my Bootstrap navbar that spans the entire width of the browser window. However, encountering some bugs as the width needs to be recalculated whenever the browser is resized. Currently, I have this cod ...

Is there a way to restrict access to a website on Chrome using HTML code?

I'm trying to block a website on Chrome using HTML. When I try, a pop-up appears. If I click OK, the site is blocked, but if I click cancel, it continues to load. How can I resolve this issue? See below for the code and screenshot: <html& ...

What is the method for displaying the word '<head>' within a <p> element in HTML code?

My HTML page contains a simple <p> tag. Within this tag, I am attempting to display some text in the following manner: Insert this code snippet into the website header, between <head> and </head>, to activate the functionality notice. ...

Ways to effectively incorporate Bootstrap into Lit?

Currently, I am in the process of converting a website from Polymer to Lit. I have made good progress with it, but I have encountered a roadblock when it comes to styling. In order to simplify development and focus on functionality, I have been following t ...

Issues with Swiper functionality in Jquery Mobile

I have implemented the Swiper plugin by idangero.us along with jQuery Mobile... In this case, I am utilizing the Scroll Container Swiper for a content slider... However, I am encountering several difficulties when trying to integrate the code... You can ...

In the thymeleaf fragment, the th:field attribute is marked with a crimson underline

I am facing an issue with a fragment that opens a modal when a button is clicked. Inside the modal, there is a form with a text field for token and submit button. However, I am getting a red squiggle underneath the th:field attribute "token", and I'm ...

Enhancing HTML "range" element with mouse scroll functionality for incrementing values in step increments

I'm working on developing a scroll feature that operates independently from the main window's scrolling function. I aim to trigger specific events in the primary window based on interactions with this separate scrollbar. The only solution I coul ...

Ways to align content in the middle within a Bootstrap div without affecting the surrounding

My initial design consisted of cards with centered text aligned inline next to icons similar to this: However, I recently received a requirement to import Bootstrap into the project and revamp the entire layout. Unfortunately, upon importing Bootstrap, th ...

Troubleshooting the issue with the htmlFor attribute

I have encountered an issue with creating radio buttons and labels using JavaScript. Despite adding the 'for' attribute in the label using 'htmlFor', it does not apply to the actual DOM Element. This results in the label not selecting t ...

How can we add styles to text entered into a form input field in a targeted way?

Is there a way to apply styling to the second word entered into a form input text field after the user hits "enter" and the data is output? In this scenario, the text always follows the format of 3 numbers, followed by a space, and then a name. For examp ...

Using Jquery to add text at the beginning of a Gmail signature

I am currently working on creating a tool using InboxSDK, which adds text to the end of an email message just before the signature. InboxSDK provides the message body as an HTML Element, and I am experimenting with using Jquery to insert the text. The chal ...