-
Notifications
You must be signed in to change notification settings - Fork 0
/
_hex-to-percent.html
82 lines (72 loc) · 2.29 KB
/
_hex-to-percent.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<!DOCTYPE html>
<!-- just a temporary page mostly written by ChatGPT to make colour matching quicker -->
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hex to RGB Converter</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
text-align: center;
padding: 20px;
}
.container {
max-width: 400px;
margin: 0 auto;
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
input[type="text"] {
width: 100%;
padding: 10px;
font-size: 16px;
border: 1px solid #ccc;
border-radius: 4px;
margin-bottom: 10px;
box-sizing: border-box;
}
button {
background-color: #4CAF50;
color: white;
padding: 10px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
}
button:hover {
background-color: #45a049;
}
p {
font-size: 18px;
margin-top: 20px;
}
</style>
</head>
<body>
<div class="container">
<h2>Hex to RGB Converter</h2>
<input type="text" id="hexInput" placeholder="Enter hex color value (e.g., #ffffff)">
<button onclick="convertHexToRGB()">Convert</button>
<p id="rgbOutput"></p>
</div>
<script>
function convertHexToRGB() {
var hex = document.getElementById('hexInput').value;
// Remove # if present
hex = hex.replace('#', '');
// Convert hex to RGB
var r = parseInt(hex.substring(0, 2), 16);
var g = parseInt(hex.substring(2, 4), 16);
var b = parseInt(hex.substring(4, 6), 16);
// Display RGB value
var rgb = '$: rgb(' + Math.round(r / 255 * 100) + '%, ' + Math.round(g / 255 * 100) + '%, ' + Math.round(b / 255 * 100) + '%);';
document.getElementById('rgbOutput').textContent = rgb;
}
</script>
</body>
</html>