How To Create Simple Popup Modal in Django Using CSS, Js in 5 Minutes - by Bilge Demirkaya - Medium
How To Create Simple Popup Modal in Django Using CSS, Js in 5 Minutes - by Bilge Demirkaya - Medium
@1)5;(
-./&0.&1)%+0%&2"(3#%&3.343
(.5+#&"6&'7+6$.&42"6$&899:
;9&"6&<&("640%2
/0&1(#2(30)4565 +-1#78 · 9#30:#)(5;
<=%.%#,6#+:;)('#>((&#%:#?:*@&5*=
Let’s create a popup modal in a Django project so that you can
store your additional info, forms, etc. Here’s my example, I have
recently created a Twitter-like website. (actually looks the same!)
!"#$%&$%'(
<div class=”bg-modal”>
<div class=”modal-content”>
</div>
</div>
position: absolute;
top:0px;
.modal-content{
width:600px;
height:300px;
background-color: white;
border:none;
border-radius: 15px;
padding:15px;
position: relative;
}
And Let’s make a button that you can close your modal.
.close{
position: absolute;
top:5px;
right: 14px;
font-size:25px;
transform: rotate(45deg); /* will make it look like x */
cursor: pointer;
}
you can Fll your HTML content now with whatever you want
inside of it.
)'*+,-&)%'(
Let’s add a little bit Javascript to make it actually work. Right now
our modal is hidden. All we want to do is click a button and open
it.
document.addEventListener(‘DOMContentLoaded’, function() {
document.getElementById(‘myBtn’).addEventListener(‘click’,
() => {
document.querySelector(‘.bg-modal’).style.display =’flex’;
});
document.querySelector(“.close”).addEventListener(‘click’,
() => {
document.querySelector(‘.bg-modal’).style.display =’none’;
});
BIJKKL>#/M
."/0'&1'2"#3454
});
E%N.'5)(#L:10:(()#5.
O7#E0&0F%:#P5&&(6
=..@*QRR10.=-,SF%3R,
All we say is;
0&1(;(30)4565
$%&&%'
If
!
the user clicks on myBtn element run a function ->
It’s a simple and sweet code which will help you to moderate and style
your website a lot. Hope this helps!