Modal Responsive
<!-- 触发按钮 -->
<button onclick="modal_responsive.showModal()" class="px-6 py-3 bg-blue-600 text-white font-medium rounded-lg shadow hover:bg-blue-700 transition-colors">
Open Responsive Modal
</button>
<!-- 响应式模态框 -->
<dialog id="modal_responsive" class="modal modal-bottom sm:modal-middle rounded-lg shadow-xl">
<div class="modal-box w-11/12 max-w-md bg-white p-0 rounded-lg">
<!-- 标题区 -->
<div class="p-4 border-b border-gray-200">
<h3 class="text-lg font-bold text-gray-900">Responsive Modal</h3>
</div>
<!-- 内容区 -->
<div class="p-4">
<p class="py-4 text-gray-600">
This modal is responsive. On mobile devices (small screens), it appears at the bottom of the screen.
On larger screens, it appears in the middle of the screen.
</p>
<p class="py-2 text-gray-600">
Resize your browser window to see how it responds to different screen sizes.
</p>
</div>
<!-- 底部按钮区 -->
<div class="p-4 border-t border-gray-200 flex justify-end">
<form method="dialog">
<button class="px-4 py-2 bg-blue-600 text-white font-medium rounded-lg shadow hover:bg-blue-700 transition-colors">
Close
</button>
</form>
</div>
</div>
</dialog>
<style>
.modal {
max-height: 90vh;
}
.modal-box {
overflow-y: auto;
}
.modal-backdrop {
background-color: rgba(0, 0, 0, 0.3);
}
.modal-bottom {
align-items: flex-end;
}
.modal-middle {
align-items: center;
}
/* Modal animation for bottom slide */
@keyframes modal-pop {
0% {
opacity: 0;
transform: translateY(20%);
}
100% {
opacity: 1;
transform: translateY(0);
}
}
.modal-bottom .modal-box {
animation: modal-pop 0.3s ease-out;
}
</style>
Copied to clipboard