결과:
예제:
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Centered Popup</title>
<style type="text/css">
body {
font-family: Arial, sans-serif;
}
.popup {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
padding: 20px;
background-color: white;
border: 1px solid #ccc;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
display: none; /* Initially hidden */
border-radius: 5px;
}
#openPopup, #closePopup {
margin-top: 20px;
}
</style>
</head>
<body>
<div id="popup" class="popup">
<p>This is a centered popup.</p>
<button id="closePopup">Close</button>
</div>
<button id="openPopup">Open Popup</button>
<script type="text/javascript">
document.getElementById('openPopup').addEventListener('click', function() {
document.getElementById('popup').style.display = 'block';
});
document.getElementById('closePopup').addEventListener('click', function() {
document.getElementById('popup').style.display = 'none';
});
</script>
</body>
</html>