Modal / 08 3D|3D
デザイン見本
CSSの`perspective`や`rotateX/Y`を活用し、ボタンやモーダル本体に奥行きと立体感を与えたデザインです。厚みを感じるリアルな質感が特徴です。
実装コード
HTML
<!-- モーダルを開くボタン -->
<button class="modal-button">3D Modal</button>
<!-- モーダルの背景マスク -->
<div class="mask"></div>
<!-- モーダル本体 -->
<div class="modal">
<div class="modal-content">
<p>【3D Modal】</p>
<p>奥行きのある3Dエフェクトのモーダルウィンドウです。</p>
<div class="close-btn-container">
<button class="close-btn">Close</button>
</div>
</div>
</div>
CSS
/* 開くボタンのスタイル */
.modal-button {
padding: 15px 30px;
background: linear-gradient(145deg, #ffffff, #e6e6e6);
color: #333;
border: none;
border-radius: 20px;
font-size: 16px;
font-weight: 700;
cursor: pointer;
transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
box-shadow:
0 8px 16px rgba(0, 0, 0, 0.1),
0 4px 8px rgba(0, 0, 0, 0.06),
inset 0 1px 0 rgba(255, 255, 255, 0.8);
transform-style: preserve-3d;
position: relative;
}
.modal-button::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: linear-gradient(145deg, #f0f0f0, #ffffff);
border-radius: 20px;
opacity: 0;
transition: opacity 0.3s ease;
z-index: -1;
}
.modal-button:hover {
transform: perspective(1000px) rotateX(-2deg) translateY(-2px);
box-shadow:
0 15px 30px rgba(0, 0, 0, 0.15),
0 8px 16px rgba(0, 0, 0, 0.1),
inset 0 1px 0 rgba(255, 255, 255, 0.9);
color: #2196f3;
}
.modal-button:active {
transform: perspective(1000px) rotateX(3deg) translateY(1px);
box-shadow:
0 4px 8px rgba(0, 0, 0, 0.1),
0 2px 4px rgba(0, 0, 0, 0.06),
inset 0 2px 4px rgba(0, 0, 0, 0.1);
}
/* 背景マスクのスタイル */
.mask {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.8);
z-index: 1001;
opacity: 0;
visibility: hidden;
transition: all 0.5s ease;
backdrop-filter: blur(12px);
pointer-events: auto;
}
.mask.appear {
opacity: 1;
visibility: visible;
}
/* モーダル本体のスタイル */
.modal {
position: fixed;
top: 50%;
left: 50%;
/* 初期状態: 縮小+3D回転 */
transform: translate(-50%, -50%) scale(0.7) rotateX(-15deg) rotateY(-5deg);
background: linear-gradient(145deg, #f8f9fa, #ffffff);
padding: 40px;
border-radius: 20px;
z-index: 1002;
opacity: 0;
visibility: hidden;
transition: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
max-width: 500px;
width: 90%;
/* 厚みを感じさせる影 */
box-shadow:
0 25px 50px rgba(0, 0, 0, 0.3),
0 15px 30px rgba(0, 0, 0, 0.2),
inset 0 1px 0 rgba(255, 255, 255, 0.8);
transform-style: preserve-3d;
perspective: 1000px;
border: 1px solid rgba(0, 0, 0, 0.1);
pointer-events: auto;
}
.modal.appear {
opacity: 1;
visibility: visible;
/* 表示時: 正面を向く */
transform: translate(-50%, -50%) scale(1) rotateX(0deg) rotateY(0deg);
}
.modal::before {
content: '';
position: absolute;
top: 0;
left: 20px;
right: 20px;
height: 1px;
background: linear-gradient(90deg, transparent, rgba(0, 0, 0, 0.1), transparent);
}
.modal p {
color: #555;
line-height: 1.7;
margin-bottom: 30px;
font-size: 16px;
font-weight: 500;
text-align: center;
}
/* 閉じるボタンのスタイル */
.close-btn {
padding: 12px 24px;
background: linear-gradient(145deg, #2196f3, #1976d2);
color: #fff;
border: none;
border-radius: 12px;
font-size: 16px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
box-shadow:
0 4px 8px rgba(33, 150, 243, 0.3),
inset 0 1px 0 rgba(255, 255, 255, 0.2);
transform-style: preserve-3d;
position: relative;
z-index: 10;
display: block;
margin: 0 auto;
}
.close-btn:hover {
background: linear-gradient(145deg, #1976d2, #1565c0);
box-shadow:
0 6px 12px rgba(33, 150, 243, 0.4),
inset 0 1px 0 rgba(255, 255, 255, 0.3);
}
.close-btn:active {
box-shadow:
0 2px 4px rgba(33, 150, 243, 0.3),
inset 0 2px 4px rgba(0, 0, 0, 0.1);
}
JS
(function () {
var btn = document.querySelector('.modal-button');
var mask = document.querySelector('.mask');
var modal = document.querySelector('.modal');
var closeBtns = document.querySelectorAll('.close-btn');
if (!btn || !mask || !modal) return;
function openModal() {
mask.classList.add('appear');
modal.classList.add('appear');
}
function closeModal() {
mask.classList.remove('appear');
modal.classList.remove('appear');
}
btn.addEventListener('click', openModal);
mask.addEventListener('click', closeModal);
closeBtns.forEach(function(b) { b.addEventListener('click', closeModal); });
document.addEventListener('keydown', function (e) {
if (e.key === 'Escape' && modal.classList.contains('appear')) {
closeModal();
}
});
})();