Floating Card Dialog
This dialog features a floating card design with subtle animations and elegant shadows. Perfect for modern web applications.
HTML
<div class="container">
<div id="dialog-container">
<button id="dialog-btn">Floating Card<br>Dialog</button>
</div>
<!-- Dialog Window -->
<div id="dialog" class="dialog">
<div class="dialog-content">
<div class="floating-header">
<div class="floating-icon">✨</div>
<span>Floating Card Dialog</span>
</div>
<div class="floating-body">
<p>This dialog features a floating card design with subtle animations and elegant shadows. Perfect for modern web applications.</p>
</div>
<div class="floating-footer">
<button class="floating-btn-secondary">Cancel</button>
<button class="floating-btn-primary">Confirm</button>
</div>
</div>
</div>
</div>
CSS
/* ダイアログコンテナスタイル */
#dialog-container {
text-align: center;
padding: 50px 20px;
}
/* ダイアログボタンスタイル */
#dialog-btn {
background-color: #007bff;
color: white;
border: none;
padding: 12px 24px;
border-radius: 6px;
cursor: pointer;
font-size: 16px;
font-weight: 500;
transition: all 0.3s ease;
min-width: 200px;
min-height: 60px;
display: inline-block;
text-align: center;
line-height: 1.4;
vertical-align: middle;
}
#dialog-btn:hover {
background-color: #0056b3;
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(0, 123, 255, 0.3);
}
/* ダイアログオーバーレイスタイル */
.dialog {
display: none;
position: fixed;
z-index: 1000;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
animation: fadeIn 0.3s;
}
/* ダイアログコンテンツスタイル */
.dialog-content {
width: 80%;
max-width: 500px;
margin: 8% auto;
animation: slideInFromTop 0.2s ease-out;
background: #ffffff;
border-radius: 20px;
box-shadow:
0 20px 60px rgba(0, 0, 0, 0.15),
0 8px 25px rgba(0, 0, 0, 0.1),
0 0 0 1px rgba(255, 255, 255, 0.8);
overflow: hidden;
transform: translateY(20px);
animation: floatIn 0.6s ease-out forwards;
position: relative;
}
.dialog-content::before {
content: '';
position: absolute;
top: -2px;
left: -2px;
right: -2px;
bottom: -2px;
background: linear-gradient(45deg, #ff6b6b, #4ecdc4, #45b7d1, #96ceb4);
border-radius: 22px;
z-index: -1;
opacity: 0.3;
animation: borderGlow 3s ease-in-out infinite alternate;
}
@keyframes floatIn {
0% {
transform: translateY(50px) scale(0.9);
opacity: 0;
}
100% {
transform: translateY(0) scale(1);
opacity: 1;
}
}
@keyframes borderGlow {
0% { opacity: 0.3; }
100% { opacity: 0.6; }
}
@keyframes shimmer {
0% { transform: translateX(-100%); }
100% { transform: translateX(100%); }
}
@keyframes bounce {
0%, 20%, 50%, 80%, 100% { transform: translateY(0); }
40% { transform: translateY(-10px); }
60% { transform: translateY(-5px); }
}
/* フローティングヘッダー */
.floating-header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 25px 20px;
text-align: center;
position: relative;
overflow: hidden;
}
.floating-header::before {
content: '';
position: absolute;
top: 0;
left: -100%;
width: 100%;
height: 100%;
background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
animation: shimmer 3s infinite;
}
.floating-icon {
font-size: 32px;
margin-bottom: 10px;
display: block;
animation: bounce 2s infinite;
}
.floating-header span {
font-size: 20px;
font-weight: 600;
position: relative;
z-index: 1;
}
/* フローティングボディ */
.floating-body {
padding: 30px 20px;
background: #ffffff;
position: relative;
}
.floating-body::before {
content: '';
position: absolute;
top: 0;
left: 20px;
right: 20px;
height: 1px;
background: linear-gradient(90deg, transparent, #e0e0e0, transparent);
}
.floating-body p {
margin: 0;
line-height: 1.7;
color: #555;
font-size: 16px;
text-align: center;
}
/* フローティングフッター */
.floating-footer {
padding: 20px;
display: flex;
gap: 15px;
justify-content: center;
background: #f8f9fa;
border-top: 1px solid #e9ecef;
}
.floating-btn-secondary {
background: transparent;
color: #6c757d;
border: 2px solid #6c757d;
padding: 10px 20px;
border-radius: 25px;
cursor: pointer;
font-size: 14px;
font-weight: 500;
transition: all 0.3s ease;
}
.floating-btn-secondary:hover {
background: #6c757d;
color: white;
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(108, 117, 125, 0.3);
}
.floating-btn-primary {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
padding: 10px 20px;
border-radius: 25px;
cursor: pointer;
font-size: 14px;
font-weight: 500;
transition: all 0.3s ease;
box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}
.floating-btn-primary:hover {
transform: translateY(-2px);
box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}
/* アニメーション */
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
@keyframes slideInFromTop {
from {
transform: translateY(-50px);
opacity: 0;
}
to {
transform: translateY(0);
opacity: 1;
}
}
/* レスポンシブ対応 */
@media (max-width: 768px) {
.dialog-content {
width: 90%;
margin: 15% auto;
padding: 15px;
}
.floating-header span {
font-size: 16px;
}
.floating-body p {
font-size: 14px;
}
}
JavaScript
// フローティングカードダイアログの機能
document.addEventListener('DOMContentLoaded', function() {
// ダイアログボタンのイベントリスナーを設定
const dialogBtn = document.getElementById('dialog-btn');
const dialog = document.getElementById('dialog');
dialogBtn.addEventListener('click', function() {
dialog.style.display = 'block';
// スクロールを無効化
document.body.style.overflow = 'hidden';
});
// 閉じるボタンのイベントリスナーを設定
const closeButtons = document.querySelectorAll('.floating-btn-secondary, .floating-btn-primary');
closeButtons.forEach(button => {
button.addEventListener('click', function() {
dialog.style.display = 'none';
// スクロールを有効化
document.body.style.overflow = 'auto';
});
});
});