Creating a pop-up effect for a div in the center of a table cell using HTML and CSS

I am currently working with Angular and facing a challenge where I need to display a div like a popup in a table cell when clicked. Despite having the click event logic in place, I am unsure of how to achieve this without using external libraries such as Bootstrap or Angular Material.

 <table>
     <tr>
       <th>Name </tr>
       <th>Age </th>
       <th>Details </th>
       <th> Blood Group</th>
       <th> Phone </th>
     </tr>

     <tr *ngFor= " let details of DetailsList; index as i" >
           <td> {{i + 1}}    <td>
           <td> {{details.name }}    <td>
           <td> {{details.age}}    <td>
           <td> <button (click)="divbox(details)"  > </button> 
           <div *ngIf="details.box" class="boxelement">
                      <button (click)="close(details)" > close</button>

               Address
               No:        {{details.address.no}}
               Area:      {{details.address.area}}
               Pincode:   {{details.address.pincode}}   
           </div>
           <td>
           <td> {{details.bloodgroup}}    <td>
           <td> {{details.phone}}    <td>
     </tr>


 </table

ts part

divbox(data){
     data.box = true

}
close(data){
    data.box = false
}


css part

.boxelement{
      background: white;
      border-radius: 2px;
      display: inline-box;
      height: 700px;
      margin: 1rem;
      position: relative;
      width: 70%;
      box-shadow: 0 19px 38px rgba(0,0,0,0.30)
}

I am looking for a way to center the popup div on the page similar to the design shown in the sample image:

Answer №1

A straightforward pop-up that is centered using flex.

You can activate it by clicking a button designated to show it, and close it by using display: none.

function openPopup(){
  document.getElementById('container').style.display = "flex";
}

function closePopup(){
  document.getElementById('container').style.display = "none";
}
#container {
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  width: 100vw;
  display: none;
    background-color: rgba(126, 125, 125, 0.5);
}

#popUP {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 200px;
  width: 200px;
  background-color: rgb(255, 197, 197);
  margin: auto;
  position: relative;
}

#popUP button {
  position: absolute;
  right:0;
  top:0;
}
<button onclick="openPopup()">Open Pop-Up</button>

<div id="container">
  <div id="popUP">My First Pop-Up <button onclick="closePopup()">X</button>
  </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

Turn off all the styles associated with a specific CSS selector

Looking for a solution to override CSS rules for the .lp-caption selector? .lp-caption { -moz-border-bottom-colors: none; -moz-border-left-colors: none; -moz-border-right-colors: none; -moz-border-top-colors: none; backgr ...

Is it possible for Angular.js timer finish event not to trigger data binding correctly?

I've been working on an AngularJS application that functions as a quiz by displaying pictures and prompting users to select the correct answer by clicking a button. The app is designed to store the user's answers in an object. Everything seems t ...

Executing multiple ajax calls and retrieving the results: A step-by-step guide

I am looking to run a series of Ajax calls and collect the responses before rendering the results for the user. The current code I am using is not working as expected because the render function is being executed before all the Ajax responses have been ga ...

Positioning the jQuery mobile navBar to be fixed on iOS 4 devices

Currently working on a mobile app with jquery using iOS4 and iOS5 compatibility as the final hurdle. While fixing the navigation bar is simple on iOS5 with position:fixed, it's not as straightforward on iOS4! I've experimented with various soluti ...

Utilize a Web Api controller to authenticate and verify the data input in

Currently, I am working on a web API application that includes the following form: <form id="editForm"> <input id="editid" type="hidden" name="id" /> <p><label>Numéro cnss </label&g ...

Ways to access the innerHTML of a specific HTML element by targeting its class using jQuery

I'm working with HTML code that looks like this: <div class="a">html value 1</div> <div class="a">html value 2</div> Is there a way to retrieve html value 1 and html value 2 using jQuery? ...

Mastering parameter passing in Node.js functions: A comprehensive guide

As I embark on my journey with node js (refer to the question), please be patient as I navigate through this new territory. To clarify my query, I have developed a function to be invoked in another JS file: exports.test = function(req, res){ connection ...

What is preventing me from adding a margin to the div directly? Why must I apply a margin to the child in order to affect the div's margin

I've encountered a strange situation with 2 fixes that seem rather unusual to me. 1: By removing the #MARGIN-30 tag and deleting the #Nav-bar tag under margin-3, the issue resolves itself when I reapply those tags. 2: Another fix is achieved by addi ...

What is the best way to show an HTML file in a WebBrowser using C++?

Currently, I'm facing the challenge of displaying an HTML file in a WebBrowser within a Windows application. The issue lies in the fact that I am dealing with a local file instead of a URL. My attempted solution with file://MyWeb.html proved unsuccess ...

The Capacitor Community Electron Platform, which combines IONIC, Angular, and Electron, encountered a TypeError: [ERR_INVALID_ARG_TYPE]. This error message indicates that the "path" argument must be in the

I have been attempting to follow the guidelines provided on to integrate the Capacitor Community Electron into a brand new Ionic Angular Test App. Everything is going smoothly until I reach the step where I need to add the platform as per the instructions ...

The HTML Email Template fails to incorporate certain CSS styles

When attempting to create an HTML Email template that includes a button with a link and has a maximum width with consistent margins on both sides, I encountered some issues. While certain parts of the CSS were applied correctly, others were not displaying ...

Surprising discovery of the reserved term 'await'

function retrieveUsers() { setTimeout(() => { displayLoadingMessage(); const response = fetch("https://reqres.in/api/users?page=1"); let userData = (await response.json()).data; storeAllUserDa ...

React - the constructor binding issue with 'this' keyword

I am a beginner in React and I am learning through creating a simple test application. However, I am facing an issue with "this" binding. I set up this app package yesterday using "create-react-app", so all the necessary plugins including babel should be u ...

Traversing JSON Data using Vanilla JavaScript to dynamically fill a specified amount of articles in an HTML page

Here is the code along with my explanation and questions: I'm utilizing myjson.com to create 12 'results'. These results represent 12 clients, each with different sets of data. For instance, Client 1: First Name - James, Address - 1234 Ma ...

Saving Information from Various MongoDB Searches on Node.js

Okay, I believe it would be more helpful if I provide my entire node.js route for you to better understand what I am trying to explain. The issue I am facing is with making multiple queries to my MongoDB database (one for each day). The queries are execut ...

What is the best way to halt the current event handler thread's execution when another event is triggered that calls the same handler at

One of the functions in my code filters and sorts contents of a select dropdown based on input text entered by the user. The function filterSort() is triggered on each keyup event from the input field. Code $(inputTextField).keyup(function() { / ...

Error in uploading files with Node.js, Multer, and Angular - issue with setting headers after they have already been sent

Working with Angular 5, Node.js, and Multer to upload a file. The process involves first saving the file to a directory and then inserting the path into the database. To begin, I created a form: <input type="file" (change)="onFileSelected($event)"> ...

Add content or HTML to a page without changing the structure of the document

UPDATE #2 I found the solution to my question through Google Support, feel free to read my answer below. UPDATE #1 This question leans more towards SEO rather than technical aspects. I will search for an answer elsewhere and share it here once I have th ...

What You See Is What You Get - A versatile tool for editing both text and

As a developer, I have encountered a common need that StackOverflow addresses. Situation I am in the process of creating a website where users can post code examples and articles using an admin system. These posts may be created by me or registered fron ...

Guidelines on launching an ionic 4 modal using routes

How can I open a modal using routes? I attempted the following approach, but it did not work as expected: ngOnInit() { this.launchModal(); } async launchModal() { const modal = await this.modalController.create({ component: AuthPasswordR ...