Even though I have added margin: auto; to .content class which is actually the content of the modal, it still positions itself at top left. Why does this happen? How can I centre align it?
var mod=document.getElementById("myModal");
var img= document.getElementById("image");
img.addEventListener("click",animate);
function animate() {
mod.style.display = "block";
}
#image {
width: 400px;
cursor: pointer;
}
.modal {
display: none;
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
z-index: 1;
background-color: rgba(0,0,0,0.9);
}
.content {
margin: auto;
width: 800px;
animation-name: zoom;
animation-duration: 0.6s;
}
@keyframes zoom {
from {transform: scale(0.1);}
to {transform: scale(1);}
}
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<img id="image" src="http://i.telegraph.co.uk/multimedia/archive/03589/Wellcome_Image_Awa_3589699k.jpg">
<div id="myModal" class="modal">
<img class="content" id="image01" src="http://i.telegraph.co.uk/multimedia/archive/03589/Wellcome_Image_Awa_3589699k.jpg">
</div>
<script src="script.js"></script>
</body>
</html>