I am using Angular. In table cell I am using div but I need to show the div like a popup in click event. I made it click event logics but how to show div element like a popup which is placed in between a table cell without using any library like bootsrap or angular material
JavaScript
x
31
31
1
<table>
2
<tr>
3
<th>Name </tr>
4
<th>Age </th>
5
<th>Details </th>
6
<th> Blood Group</th>
7
<th> Phone </th>
8
</tr>
9
10
<tr *ngFor= " let details of DetailsList; index as i" >
11
<td> {{i + 1}} <td>
12
<td> {{details.name }} <td>
13
<td> {{details.age}} <td>
14
<td> <button (click)="divbox(details)" > </button>
15
<div *ngIf="details.box" class="boxelement">
16
<button (click)="close(details)" > close</button>
17
18
Address
19
No: {{details.address.no}}
20
Area: {{details.address.area}}
21
Pincode: {{details.address.pincode}}
22
</div>
23
<td>
24
<td> {{details.bloodgroup}} <td>
25
<td> {{details.phone}} <td>
26
</tr>
27
28
29
</table
30
31
ts part
JavaScript
1
10
10
1
divbox(data){
2
data.box = true
3
4
}
5
close(data){
6
data.box = false
7
}
8
9
10
css part
JavaScript
1
12
12
1
.boxelement{
2
background: white;
3
border-radius: 2px;
4
display: inline-box;
5
height: 700px;
6
margin: 1rem;
7
position: relative;
8
width: 70%;
9
box-shadow: 0 19px 38px rgba(0,0,0,0.30)
10
}
11
12
I need to this div like a popup in the center of the page is that possible
sample image from internet
https://wisepops.com/wp-content/uploads/2017/12/Nike-popup-1.png
Advertisement
Answer
A simple pop-up which is centered using flex
.
You can trigger it by click of button defined to show it and close it using display: none
.
JavaScript
1
7
1
function func(){
2
document.getElementById('container').style.display = "flex";
3
}
4
5
function funcClose(){
6
document.getElementById('container').style.display = "none";
7
}
JavaScript
1
26
26
1
#container {
2
position: fixed;
3
top: 0;
4
left: 0;
5
height: 100vh;
6
width: 100vw;
7
display: none;
8
background-color: rgba(126, 125, 125, 0.5);
9
}
10
11
#popUP {
12
display: flex;
13
justify-content: center;
14
align-items: center;
15
height: 200px;
16
width: 200px;
17
background-color: rgb(255, 197, 197);
18
margin: auto;
19
position: relative;
20
}
21
22
#popUP button {
23
position: absolute;
24
right:0;
25
top:0;
26
}
JavaScript
1
6
1
<button onclick="func()">Pop me UP</button>
2
3
<div id="container">
4
<div id="popUP">My first Pop UP <button onclick="funcClose()">X</button>
5
</div>
6
</div>