帮我用Html做一个弹窗,好看一点
时间: 2023-05-14 14:04:30 浏览: 58
当然可以,以下是一个简单的HTML弹窗的代码:
```html
<!DOCTYPE html>
<html>
<head>
<title>弹窗示例</title>
<style type="text/css">
.popup {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: #fff;
padding: 20px;
box-shadow: 0 0 10px rgba(0,0,0,0.3);
border-radius: 5px;
z-index: 999;
}
.popup h2 {
margin-top: 0;
}
.popup button {
background-color: #007bff;
color: #fff;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
}
</style>
</head>
<body>
<button onclick="showPopup()">显示弹窗</button>
<div id="popup" class="popup" style="display:none;">
<h2>这是一个弹窗</h2>
<p>弹窗内容可以在这里添加</p>
<button onclick="hidePopup()">关闭弹窗</button>
</div>
<script type="text/javascript">
function showPopup() {
document.getElementById("popup").style.display = "block";
}
function hidePopup() {
document.getElementById("popup").style.display = "none";
}
</script>
</body>
</html>
```
你可以根据需要修改样式和内容。