即使我已經添加了保證金:auto; .content類實際上是模態的內容,它仍然位於左上角。爲什麼會發生?我怎樣才能對齊它?爲什麼使用margin:auto;不工作?
var mod=document.getElementById("myModal");
var img= document.getElementById("image");
img.addEventListener("click",animate);
function animate() {
\t mod.style.display = "block";
}
#image {
width: 400px;
\t cursor: pointer;
}
.modal {
\t display: none;
\t position: fixed;
\t left: 0;
\t top: 0;
\t width: 100%;
\t height: 100%;
\t z-index: 1;
background-color: rgba(0,0,0,0.9);
}
.content {
\t margin: auto;
\t width: 800px;
\t animation-name: zoom;
\t animation-duration: 0.6s;
}
@keyframes zoom {
\t from {transform: scale(0.1);}
to {transform: scale(1);}
}
<html>
<head>
\t <link rel="stylesheet" href="style.css">
\t </head>
\t <body>
\t <img id="image" src="http://i.telegraph.co.uk/multimedia/archive/03589/Wellcome_Image_Awa_3589699k.jpg">
\t \t <div id="myModal" class="modal">
\t \t \t <img class="content" id="image01" src="http://i.telegraph.co.uk/multimedia/archive/03589/Wellcome_Image_Awa_3589699k.jpg">
\t \t </div>
<script src="script.js"></script> \t \t
\t </body>
</html>
添加該文本對齊:中心.MODEL類如.. .modal {文本對齊:中心;} – krishna