html弹窗字体不同颜色
时间: 2023-07-11 22:36:10 浏览: 117
要让 HTML 弹窗中的文字显示不同的颜色,可以使用 CSS 样式来实现。以下是一个示例代码:
<!DOCTYPE html>
<html>
<head>
<title>弹窗示例</title>
<style>
#popup {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
padding: 20px;
background-color: #fff;
border: 1px solid #ccc;
}
.red {
color: red;
}
.blue {
color: blue;
}
</style>
</head>
<body>
<button onclick="showPopup()">点击弹出窗口</button>
<div id="popup" style="display:none;">
<p>这是一个弹出窗口</p>
<p class="red">这段文字是红色的</p>
<p class="blue">这段文字是蓝色的</p>
<button onclick="hidePopup()">关闭</button>
</div>
<script>
function showPopup() {
document.getElementById("popup").style.display = "block";
}
function hidePopup() {
document.getElementById("popup").style.display = "none";
}
</script>
</body>
</html>
在这个示例代码中,我们使用了两个 CSS 类 .red
和 .blue
,分别用于设置红色和蓝色的文字颜色。在弹窗的 HTML 内容中,我们使用 <p>
标签来包含需要设置颜色的文字,并给它们添加相应的类。这样就能实现弹窗中不同文字颜色的效果了。
相关推荐
















