<!DOCTYPE html>
<html>
<head>
<style>
body { font-family: Arial; }
.modal {
display: none;
position: fixed;
top: 0; left: 0; right: 0; bottom: 0;
background: rgba(0,0,0,0.5);
justify-content: center;
align-items: center;
}
.modal:target {
display: flex; /* Show when targeted */
}
.modal-content {
background: white;
padding: 20px;
border-radius: 10px;
width: 300px;
}
</style>
</head>
<body>
<a href="#myModal">Open Modal</a>
<div id="myModal" class="modal">
<div class="modal-content">
<h3>Modal Title</h3>
<p>This is a CSS-only modal.</p>
<a href="#">Close</a>
</div>
</div>
</body>
</html>
Explanation:
- Uses CSS
:target
selector instead of JS. - Clicking link shows the modal.
Leave a Reply