



HTML・CSSのみで実装するポップアップ・モーダルウィンドウのデザイン3選
ユーザーへの通知・補足・詳細な情報の表示など様々な用途に使われるポップアップ・モーダルウィンドウ。今回はそんなモーダルをコピペだけで取り入れることができるデザインスニペットをまとめました。JavaScriptを使わずHTML・CSSのみで実装しているものなのでカスタマイズのハードルも低めです。

リンク風のモーダル
step1
デザインを調整する
ここにモーダルの中身が入ります。ここにモーダルの中身が入ります。
ここにモーダルの中身が入ります。ここにモーダルの中身が入ります。
ここにモーダルの中身が入ります。ここにモーダルの中身が入ります。
ここにモーダルの中身が入ります。ここにモーダルの中身が入ります。
ここにモーダルの中身が入ります。ここにモーダルの中身が入ります。
step2
HTMLをコピペする
HTML
<div class="modal-001__wrap">
<input type="radio" id="modal-001__open" class="modal-001__open-input" name="modal-001__trigger"/>
<label for="modal-001__open" class="modal-001__open-label">モーダルを開く</label>
<input type="radio" id="modal-001__close" name="modal-001__trigger"/>
<div class="modal-001">
<div class="modal-001__content-wrap">
<label for="modal-001__close" class="modal-001__close-label">×</label>
<div class="modal-001__content">ここにモーダルの中身が入ります。ここにモーダルの中身が入ります。<br/>ここにモーダルの中身が入ります。ここにモーダルの中身が入ります。<br/>ここにモーダルの中身が入ります。ここにモーダルの中身が入ります。</div>
</div>
<label for="modal-001__close">
<div class="modal-001__background"></div>
</label>
</div>
</div>
step3
CSSをコピペする
CSS
.modal-001__wrap {
display: inline-block;
}
.modal-001__wrap input {
display: none;
}
.modal-001__open-label,
.modal-001__close-label {
cursor: pointer;
}
.modal-001__open-label {
color: #4f96f6;
font-size: .95em;
}
.modal-001__open-label:hover {
text-decoration: underline;
cursor: pointer;
color: #c7511f;
}
.modal-001 {
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
z-index: 9999;
display: none;
}
.modal-001__open-input:checked + label + input + .modal-001 {
display: block;
animation: modal-001-animation .6s;
}
.modal-001__content-wrap {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
width: 80%;
max-width: 650px;
background-color: #fefefe;
z-index: 2;
border-radius: 5px;
}
.modal-001__close-label {
background-color: #777;
color: #fff;
border: 2px solid #fff;
border-radius: 20px;
width: 36px;
height: 36px;
line-height: 1.5;
text-align: center;
display: table-cell;
position: fixed;
top: -15px;
right: -2%;
z-index: 99999;
font-size: 1.4em;
}
.modal-001__content {
max-height: 50vh;
overflow-y: auto;
padding: 39px 45px 40px;
}
.modal-001__background {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, .45);
z-index: 1;
}
@keyframes modal-001-animation {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
@media only screen and (max-width: 520px) {
.modal-001__open-label {
max-width: 90%;
padding: .94em 2.1em .94em 2.6em;
}
.modal-001__close-label {
top: -17px;
right: -4%;
}
.modal-001__content-wrap {
width: 90vw;
}
.modal-001__content {
padding: 33px 21px 35px;
max-width: 100%;
}
}

ボタン風のモーダル
step1
デザインを調整する
ここにモーダルの中身が入ります。ここにモーダルの中身が入ります。
ここにモーダルの中身が入ります。ここにモーダルの中身が入ります。
ここにモーダルの中身が入ります。ここにモーダルの中身が入ります。
ここにモーダルの中身が入ります。ここにモーダルの中身が入ります。
ここにモーダルの中身が入ります。ここにモーダルの中身が入ります。
step2
HTMLをコピペする
HTML
<div class="modal-002__wrap">
<input type="radio" id="modal-002__open" class="modal-002__open-input" name="modal-002__trigger"/>
<label for="modal-002__open" class="modal-002__open-label">モーダルを開く</label>
<input type="radio" id="modal-002__close" name="modal-002__trigger"/>
<div class="modal-002">
<div class="modal-002__content-wrap">
<label for="modal-002__close" class="modal-002__close-label">×</label>
<div class="modal-002__content">ここにモーダルの中身が入ります。ここにモーダルの中身が入ります。<br/>ここにモーダルの中身が入ります。ここにモーダルの中身が入ります。<br/>ここにモーダルの中身が入ります。ここにモーダルの中身が入ります。</div>
</div>
<label for="modal-002__close">
<div class="modal-002__background"></div>
</label>
</div>
</div>
step3
CSSをコピペする
CSS
.modal-002__wrap input {
display: none;
}
.modal-002__open-label,
.modal-002__close-label {
cursor: pointer;
}
.modal-002__open-label {
display: flex;
justify-content: center;
align-items: center;
width: 250px;
margin:0 auto;
padding: .8em 2em;
border: none;
border-radius: 5px;
background-color: #2589d0;
color: #ffffff;
font-weight: 600;
font-size: 1em;
}
.modal-002__open-label:hover {
background-color: #fff;
color: #2589d0;
outline: 1px solid #2589d0;
}
.modal-002 {
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
z-index: 9999;
display: none;
}
.modal-002__open-input:checked + label + input + .modal-002 {
display: block;
animation: modal-002-animation .6s;
}
.modal-002__content-wrap {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
width: 80%;
max-width: 650px;
background-color: #fefefe;
z-index: 2;
border-radius: 5px;
}
.modal-002__close-label {
background-color: #777;
color: #fff;
border: 2px solid #fff;
border-radius: 20px;
width: 36px;
height: 36px;
line-height: 1.6;
text-align: center;
display: table-cell;
position: fixed;
top: -15px;
right: -2%;
z-index: 99999;
font-size: 1.3em;
}
.modal-002__content {
max-height: 50vh;
overflow-y: auto;
padding: 39px 45px 40px;
}
.modal-002__background {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, .45);
z-index: 1;
}
@keyframes modal-002-animation {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
@media only screen and (max-width: 520px) {
.modal-002__open-label {
max-width: 90%;
padding: .94em 2.1em .94em 2.6em;
}
.modal-002__close-label {
top: -17px;
right: -4%;
}
.modal-002__content-wrap {
width: 90vw;
}
.modal-002__content {
padding: 33px 21px 35px;
max-width: 100%;
}
}

WordPressのショートコードで呼び出せるモーダル
step1
functions.phpにコピペする
PHP
/**************************
* 記事内モーダル
***************************/
function entry_modal($atts, $content = null)
{
if (is_null($atts)) {
return '';
}
extract(shortcode_atts([
'label' => '',
'label_class' => '',
], $atts));
if (!($label && $content)) {
return '';
}
$content = do_shortcode(shortcode_unautop($content));
$inputRandId1 = mt_rand(1, 99999);
$inputRandId2 = mt_rand(1, 99999);
$inputRandName = mt_rand(1, 99999);
$entryModalPareClass = '';
$modalLabel = "<label for='modal__trigger{$inputRandId1}' class='open-label'>{$label}</label>";
if ($labelClass) {
$modalLabel = "<label for='modal__trigger{$inputRandId1}' class='open-label {$label_class}'>{$label}</label>";
}
$output = <<<EOF
<div class="modal-pare{$entryModalPareClass}">
<input type="radio" id="modal__trigger{$inputRandId1}" class="modal__open" name="modal__trigger{$inputRandName}">
{$modalLabel}
<input type="radio" id="modal__trigger{$inputRandId2}" class="modal__close" name="modal__trigger{$inputRandName}">
<div class="modal">
<div class="modal__content-wrap">
<label for="modal__trigger{$inputRandId2}" class="close-label">×</label>
<div class="modal__content">{$content}</div>
</div>
<label for="modal__trigger{$inputRandId2}">
<div class="modal__background"></div>
</label>
</div>
</div>
EOF;
return $output;
}
add_shortcode('entry_modal', 'entry_modal');
step2
CSSをコピペする
CSS
.modal-wrap input {
display: none;
}
.open-label,
.close-label {
cursor: pointer;
}
.open-label.simple {
color: #4f96f6;
font-size: .95em;
}
.open-label.simple:hover {
text-decoration: underline;
cursor: pointer;
color: #c7511f
}
.open-label.button {
padding: .84em 3.3em .84em 3.8em;
font-weight: bold;
font-size: .9em;
background-color: #2589d0;
color: #fff;
border-radius: 5px;
display: inline-block;
margin: 0 auto 1em;
text-align: center;
letter-spacing: .01em;
}
.open-label.button:hover {
outline: 1px solid rgb(255, 179, 107);
color: #2589d0;
background-color: #fff;
}
.open-label.button:hover:after {
color: #2589d0;
}
.open-label.button:after {
font-family: 'Font Awesome 5 Free';
font-weight: 900;
content: "\f138";
display: inline-block;
padding-left: 8px;
color: #fff;
}
.modal {
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
z-index: 9999;
display: none;
}
.modal__open:checked + label + input + .modal {
display: block;
animation: modal-animation .6s;
}
.modal__content-wrap {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
width: 80%;
max-width: 650px;
background-color: #fefefe;
z-index: 2;
border-radius: 5px;
}
.close-label {
background-color: #777;
color: #fff;
border: 2px solid #fff;
border-radius: 20px;
width: 36px;
height: 36px;
line-height: 1.6;
text-align: center;
display: table-cell;
position: fixed;
top: -15px;
right: -2%;
z-index: 99999;
font-size: 1.3em;
}
.modal__content {
max-height: 50vh;
overflow-y: auto;
padding: 39px 45px 40px;
}
.modal__background {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, .45);
z-index: 1;
}
@keyframes modal-animation {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
@media only screen and (max-width: 480px) {
.open-label.button {
max-width: 90%;
padding: .94em 2.1em .94em 2.6em;
}
.close-label {
top: -17px;
right: -4%;
}
.modal__content-wrap {
width: 90vw;
}
.modal__content {
padding: 33px 21px 35px;
max-width: 100%;
}
}
step3
ショートコードを呼び出す
[entry_modal label="ここにラベル" label_class="ここにボタンの種類(simple or button)"]ここにモーダルの中身[/entry_modal]