[パーツ]モーダルウィンドウ ボタンを押すと中心からモーダルウィンドウが開く

CSS HTML
 2018.02.09
 2018.07.09

ボタンを押すと中心からモーダルウィンドウが開く

ボタンを押すと中心からモーダルウィンドウが開くタイプです。

browser:  65 11 20 11 
ニャン易度 
<div class="cp_modal02">
<input type="checkbox" id="cp_modal" />
<h1>h1テキスト</h1>
<p>テキスト</p>
<label for="cp_modal" class="cp_modal_btn"></label>
<label for="cp_modal" class="cp_modal_bg"></label>
<div class="cp_modal_cont">
<label for="cp_modal" class="cp_close"><i class="fa fa-times" aria-hidden="true"></i></label>
	<header>
		<h2>h2テキスト</h2>
	</header>
	<article class="cp_content">
		<p>テキスト</p>
		<p class="citation">テキスト</p>
	</article>
	<footer><label for="cp_modal" class="cp_btn cp_cl">閉じる</label></footer>
</div>
</div>
body {
	box-sizing: border-box;
	margin: 0;
	padding: 0;
}
*, *::after, *::before {
	box-sizing: inherit;
}
*, *:before, *:after {
	box-sizing: border-box;
	outline: none;
}
.cp_modal02 {
	position: relative;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	width: 100%;
	height: 100vh;
	font-size: 16px;
	font-weight: 300;
	line-height: 1.5;
	color: #444444;
}
.cp_modal02:before {
	position: absolute;
	content: '';
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	background-color: rgba(255, 255, 255, 0.7);
	z-index: -1;
}
.cp_modal02 .cp_content p {
	margin: 0;
	line-height: 1.5;
	text-indent: 1em;
}
.cp_modal02 p.citation {
	text-align: right;
}
.cp_modal02 p.citation::before {
	content: '00'
}
.cp_modal02 p:not(.citation) {
	margin-bottom: 1.5rem;
}
.cp_modal02 a {
	text-decoration: none;
}
.cp_modal02 label {
	cursor: pointer;
}
.cp_modal02 .cp_modal_btn {
	position: relative;
	display: table-cell;
	width: 100px;
	height: 100px;
	background-color: #00bcd4;
	box-shadow: 0 0 40px rgba(0, 0, 0, 0.3);
	border-radius: 50%;
	text-align: center;
	transition: box-shadow 250ms ease;
	color: #ffffff;
}
.cp_modal02 .cp_modal_btn::before {
	position: absolute;
	top:50%;
	left: 20%;
	font-family: 'FontAwesome';
	content: '\f0a6' ' よむ';
	font-size: 1em;
	line-height: 0;
	display: inline-block;
	width: 4em;
	color: #ffffff;
}
.cp_modal02 .cp_modal_btn:hover {
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
}
.cp_modal02 .cp_modal_bg {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	opacity: 0;
	z-index: 10;
	visibility: hidden;
	transition: background-color 250ms linear;
}
.cp_modal02 .cp_modal_cont {
	position: absolute;
	top: 45%;
	left: 50%;
	width: 50%;
	height: 50%;
	overflow-y: scroll;
	margin-top: -18%;
	margin-left: -25%;
	padding: 30px;
	background-color: white;
	border-radius: 4px;
	box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
	transform: scale(0);
	transition: transform 250ms ease;
	visibility: hidden;
	z-index: 20;
}
.cp_modal02 .cp_modal_cont .cp_close {
	position: relative;
	float: right;
	font-size: 18px;
	transition: transform 500ms ease;
	z-index: 11;
}
.cp_modal02 .cp_modal_cont .cp_close:hover {
	color: #da3c41;
	transform: rotate(180deg);
}
.cp_modal02 .cp_modal_cont header {
	position: relative;
	display: block;
	border-bottom: 1px solid #00bcd4;
	margin-bottom: 1.5em;
}
.cp_modal02 .cp_modal_cont header h2 {
	margin: 0 0 10px;
	padding: 0;
	font-size: 28px;
}
.cp_modal02 .cp_modal_cont article {
	position: relative;
	display: block;
	margin: 0;
	padding: 0;
	font-size: 16px;
	line-height: 1.75;
}
.cp_modal02 .cp_modal_cont footer {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: flex-end;
	width: 100%;
	margin: 0;
	padding: 10px 0 0;
}
.cp_modal02 .cp_modal_cont footer .cp_btn {
	position: relative;
	padding: 10px 30px;
	border-radius: 3px;
	font-size: 14px;
	font-weight: 400;
	color: white;
	text-transform: uppercase;
	overflow: hidden;
}
.cp_modal02 .cp_modal_cont footer .cp_btn:before {
	position: absolute;
	content: '';
	top: 0;
	left: 0;
	width: 0;
	height: 100%;
	background-color: rgba(88, 24, 26, 0.3);
	transition: width 250ms ease;
	z-index: 0;
}
.cp_modal02 .cp_modal_cont footer .cp_btn:hover:before {
	width: 100%;
}
.cp_modal02 .cp_modal_cont footer .cp_btn.cp_cl {
	background-color: #da3c41;
}
.cp_modal02 #cp_modal {
  display: none;
}
.cp_modal02 #cp_modal:checked ~ .cp_modal_bg {
	visibility: visible;
	background-color: #000000;
	opacity: 0.7;
	transition: background-color 250ms linear;
}
.cp_modal02 #cp_modal:checked ~ .cp_modal_cont {
	visibility: visible;
	transform: scale(1);
	transition: transform 250ms ease;
	z-index: 111;
}
@media only screen and (max-width: 480px) {
	.cp_modal02 .cp_modal_cont{
		top: 30%;
		left: 30%;
		width: 90%;
	}
}

copypet.jp

CSS3などで新たに追加された要素・装飾方法など、日々コードを書いていないと忘れてしまったり、ささっとプロトタイプを作る時などちょっとしたことに時間をかけている暇はない。そんな時に「あ〜、あれストックしときゃよかったなぁ」って困った自分用のストックブログです。カスタマイズなどがしやすいよう、昨今のweb制作に取り入れられる一般的なコードを中心に掲載しています。

More Info

こんな記事はいかがですか?