What is the best way to utilize "position:fixed" in order to attach an image to a pop-up div?

On my website, I have a div that functions like a pop-up when triggered by an icon click. This pop-up allows scrolling within itself while disabling scrolling on the rest of the website. However, I'm facing an issue with positioning a fixed image for the "close" button only within this pop-up div. The challenge is to make sure the close image is hidden until the pop-up is displayed and disappears when it's closed. Currently, I've used "position:absolute" which works for showing the close button only within the pop-up but requires users to scroll back up to see it again after closing the pop-up.

Answer №1

Try it out in this interactive demo

If you're looking to use absolute positioning, it could work well for your needs. Just remember to keep the close button outside of the scrollable area and on the same level as the wrapper.

Here's an example of how you can structure your HTML:

<div class="popup">
    <div class="popup-content-wrap">
        <div class="popup-content"></div>
    </div>
    <div class="close">close</div>
</div>

And here's the CSS to go along with it:

.popup {
    position: fixed;
    background-color: blue;
    left: 50px;
    right: 50px;
    bottom: 50px;
    top: 50px;
}
.popup-content-wrap {
    height: 100%;
    width: 100%;    
    overflow: auto;
}
.popup-content {
    height: 1000px;
}
.close {
    position: absolute;
    bottom: 20px;
    right: 20px;
}

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

Incorporating a self-invoking anonymous function to enhance Sir Trevor within an AngularJS framework while also making use of

I recently started working with AngularJS and I have an App where I am using the Sir Trevor content editor. I want to add some custom blocks to the editor by extending it, but I am having trouble accessing angular services within my extension code. The ext ...

How to use .sort() and .data() to arrange HTML elements in Internet Explorer 11 and Microsoft Edge

I found the solution to sorting elements using data id in jQuery from this question on Stack Overflow. It helped me make progress on a project I've been working on. The top-rated answer pointed out that using jQuery's .data() is necessary for co ...

Create a new one-dimensional array by stacking the columns of a matrix

In my current project, I am dealing with a complex array of arrays where each inner array contains objects. My goal is to transform this multidimensional array into a flat array organized in a column-wise order. Here is the code snippet that I have implem ...

Best Practices for Installing Webpack in a Client/Server Folder Structure

Working on a React Nodejs web application and in the process of figuring out how to bundle the frontend using webpack. This is how my project's structured: Where exactly do I need to install webpack and configure webpack.config.js? I've noticed ...

Issue with cloning InvokedOn text from the context menu

Check out my fiddle at http://jsfiddle.net/X9tgY/1526/ The following line of code is not functioning correctly: $(selectedText).clone().insertAfter(selectedText); When I right click on the HTML text, I am able to retrieve the HTML of the invokedOn text ...

What are the steps to effectively utilize my search bar alongside Google Custom Search?

Here is the HTML code for my form: <form action="#" class="searh-holder"> <input name="se" id="se" type="text" class="search" placeholder="Search.." value="" /> <button class="search-submit" id="submit_btn"><i class="fa fa-sea ...

Guide on transforming Json information into the preferred layout and iterating through the loop

Currently, I am diving deep into the world of JSON and feeling a bit puzzled by data formats, arrays, objects, and strings. First things first, I'm in need of data structured like this (on a jQuery page). Would this be considered an object or an arra ...

Chrome automatically scrolling back to the beginning of the page following a remote form submission

Rails Version: 5.2.2 Chrome Version: 78.0.3904.87 While testing my website on Chrome today, I encountered an issue where the page automatically scrolls to the top whenever an AJAX request is made. This problem only occurs in Chrome and not in other brows ...

In the realm of Javascript, the postAjax function fails to successfully post any content

Good day! I have been working on a small AJAX application, using this function as a foundation, with PHP as the server-side language. Below is the JavaScript code being employed: var data = {}; data.name = document.getElementById('name').value ...

Curious about the thumbnail icon in mobile Chrome? Find out how you can incorporate it into your website!

I'm seeking assistance in identifying the name of this icon and how to properly implement it on my website. Any guidance would be greatly appreciated. https://i.sstatic.net/GoA6o.jpg ...

Master the ins and outs of working with Angular and Webpack on

Encountering issues with the webpack-angular tutorial from egghead.io during the "ES6 with Babel" step. Requesting assistance in resolving the problem. Stuck at this specific step while following the tutorial: Error message in Chrome devTools: ........ ...

Combine the remaining bars by stacking the highest one on top in Highchart

Making use of stacking to display the highest value as the longest column/bar, with smaller values being merged within the highest one, can create a more visually appealing stack chart. For example, when looking at Arsenal with values of 14 and 3, ideally ...

Leverage the AJAX response data for another JavaScript function

I am interested in utilizing the data received from an AJAX response in another JavaScript function. Here is the AJAX call located in the view file (sell_report.php): <script src="<?php echo base_url(); ?>public/js/jquery-1.12.4.min.js"> ...

The received URL from the POST request in React is now being opened

After completing an API call, I successfully received the correct response in my console. Is there a way to redirect my React app from the local host to the URL provided (in this case, the one labeled GatewayUrl under data)? Any assistance would be greatly ...

Display the poster image by pausing the video on an HTML webpage

Check out this code snippet: <video id="primorvid" onclick="this.paused ? this.play() : this.pause();" poster="http://primor.m-sites.co.il/wp-content/uploads/2016/08/Untitled-18.jpg" width="1903" height="564"> <source src="http://primor.m-sites.c ...

Thymeleaf is responsible for fetching the static resources by referencing the REST URI

I am currently utilizing thymeleaf as my chosen template engine for a spring boot project. Here is the directory structure: src/main/ |- java | - UserAdministrationController.java |- resources | - static | - admin | - css ...

What steps should I take to address the issue of the document not being defined?

I encountered an error that I initially thought was related to node.js, but now I'm not entirely sure. How can I go about resolving this issue? [Running] node "c:\Users\Lenovo\Desktop\projectjs\index.js" c:\User ...

What is the best way to showcase a div on top of all other elements in an HTML page?

As a newcomer to html and css, I have successfully created a div that contains city names. The issue I am currently facing is when I click on a button to display the div, it gets hidden behind the next section of my page. Take a look at the image below for ...

Opt for CSS (or JavaScript) over SMIL for better styling and animation control

I recently noticed an alert in my Chrome console that SVG's SMIL animations are being deprecated and will soon be removed. The message suggested using CSS or Web animations instead. Since I want to transition from SMIL to CSS animations, there are a ...

Is there a way to determine which label in the Material UI default theme affects the default border color, specifically excluding the focus or hover border?

I am currently using the 'createTheme' function to personalize the theme of my TextField input component in Material UI. To implement the desired changes, I am referring to the default theme for Material UI on https://mui.com/customization/defau ...