CSS 弹窗

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6

弹窗

在这里插入图片描述

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>弹窗</title>
		<style type="text/css">
			.alert {
				display: none;
				justify-content: center;
				align-items: center;
				width: 100%;
				height: 100vh;
				background: rgba(0, 0, 0, 0.4);
				position: fixed;
				top: 0;
				left: 0;
			}

			.alert-body {
				width: 450px;
				background-color: white;
				border-radius: 10px;
				font-size: 30px;
				color: #000;
				text-align: center;
				animation: moveFromTop 0.3s linear;
			}

			.alert-title {
				line-height: 80px;
				border-bottom: 2px solid #eee;
				font-size: 30px;
				position: relative;
			}

			.close {
				position: absolute;
				top: 22px;
				right: 30px;
				width: 40px;
				height: 40px;
				line-height: 40px;
				cursor: pointer;
				color: grey;
			}

			.close:hover {
				color: black;
			}

			.alert-content {
				display: flex;
				justify-content: center;
				align-items: center;
				height: 150px;
				color: #999;
			}

			@keyframes moveFromTop {
				from {
					margin-top: -600px;
				}

				to {
					margin-top: 0;
				}
			}
		</style>
	</head>
	<body>
		<button id="btn">显示弹窗</button>
		<div class="alert">
			<div class="alert-body">
				<div class="alert-title">标题<div class="close">x</div>
				</div>
				<div class="alert-content">hello world</div>
			</div>
		</div>
		<script type="text/javascript">
			let btn = document.getElementById("btn");
			let alert = document.querySelector(".alert");
			let close = document.querySelector(".close");
			btn.onclick = function() {
				alert.style.display = "flex";
			};
			close.onclick = function() {
				alert.style.display = "none";
			};
			alert.onclick = function(e) {
				if (e.target == alert) {
					alert.style.display = "none";
				}
			};
		</script>
	</body>
</html>
阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6
标签: CSS