HTML 点击文字弹出自适应居中弹窗代码示例 - 完整教程
<!DOCTYPE html>
<html>
<head>
<style>
/* 弹窗样式 */
.popup {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
z-index: 9999;
}
<pre><code> .popup-content {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: #fff;
padding: 20px;
border-radius: 5px;
}
/* 文字点击样式 */
.clickable-text {
cursor: pointer;
text-decoration: underline;
}
</style>
</code></pre>
</head>
<body>
<p>点击下面的文字弹出弹窗:</p>
<p class="clickable-text" onclick="showPopup()">点击弹窗</p>
<pre><code><div id="popup" class="popup">
<div class="popup-content">
<h2>这是一个弹窗</h2>
<p>这是弹窗的内容。</p>
<button onclick="hidePopup()">关闭弹窗</button>
</div>
</div>
<script>
function showPopup() {
document.getElementById("popup").style.display = "block";
}
function hidePopup() {
document.getElementById("popup").style.display = "none";
}
</script>
</code></pre>
</body>
</html>
原文地址: https://www.cveoy.top/t/topic/l0AO 著作权归作者所有。请勿转载和采集!