File: /var/www/html/private/颜色代码查看器.html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>颜色代码查看器</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 600px;
margin: 0 auto;
padding: 20px;
text-align: center;
}
.container {
margin-top: 50px;
}
input {
padding: 10px;
width: 150px;
font-size: 16px;
margin-right: 10px;
}
button {
padding: 10px 20px;
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
font-size: 16px;
}
button:hover {
background-color: #45a049;
}
.color-display {
width: 200px;
height: 200px;
margin: 30px auto;
border: 1px solid #ddd;
border-radius: 10px;
display: flex;
align-items: center;
justify-content: center;
font-weight: bold;
color: white;
text-shadow: 1px 1px 1px black;
}
.info {
margin-top: 20px;
padding: 10px;
background-color: #f8f8f8;
border-radius: 5px;
}
</style>
</head>
<body>
<h1>颜色代码查看器</h1>
<div class="container">
<input type="text" id="colorInput" placeholder="输入颜色代码" value="#FF0000">
<button onclick="showColor()">显示颜色</button>
<div class="color-display" id="colorDisplay">颜色预览</div>
<div class="info">
<p>支持的颜色格式:</p>
<p>十六进制: #FF0000, #F00</p>
<p>RGB: rgb(255, 0, 0)</p>
<p>RGBA: rgba(255, 0, 0, 0.5)</p>
<p>HSL: hsl(0, 100%, 50%)</p>
<p>颜色名称: red, blue, green等</p>
</div>
</div>
<script>
function showColor() {
const colorInput = document.getElementById('colorInput').value;
const colorDisplay = document.getElementById('colorDisplay');
// 尝试设置背景颜色
colorDisplay.style.backgroundColor = colorInput;
// 检查颜色是否有效
const computedColor = window.getComputedStyle(colorDisplay).backgroundColor;
if (computedColor === 'rgba(0, 0, 0, 0)') {
colorDisplay.textContent = '无效颜色代码';
colorDisplay.style.backgroundColor = 'white';
} else {
colorDisplay.textContent = colorInput;
}
}
// 初始加载时显示默认颜色
window.onload = showColor;
</script>
</body>
</html>