<html><head><base href="https://tip-calculator.example.com#about">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Random Color Generator</title>
<style>
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
padding: 20px;
font-size: 20px;
font-family: Arial, sans-serif;
}
.random-color-generator-container {
display: flex;
gap: 20px;
max-width: 1200px;
margin: 0 auto;
}
.hex-color-container, .rgb-color-container {
min-height: 100vh;
flex: 1;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
transition: all 0.3s ease;
}
.hex-color-container:hover, .rgb-color-container:hover {
transform: translateY(-5px);
box-shadow: 0 6px 8px rgba(0, 0, 0, 0.15);
}
button {
padding: 12px 20px;
cursor: pointer;
font-size: 18px;
font-weight: bold;
border: none;
border-radius: 5px;
transition: all 0.3s ease;
}
button:hover {
opacity: 0.9;
}
.hex-color-container button {
background-color: rgb(230, 246, 127);
}
.rgb-color-container {
display: flex;
flex-direction: column;
gap: 20px;
}
.hex-color-container {
background-color: #4CAF50;
padding: 20px;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
gap: 30px;
}
.hex-color-value, .rgb-color-value {
font-size: 30px;
font-weight: bold;
color: #fff;
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
}
.rgb-color-container {
background-color: rgb(0, 255, 247);
padding: 20px;
display: flex;
justify-content: center;
align-items: center;
}
.rgb-color-container button {
background-color: rgb(208, 48, 125);
color: #fff;
}
input[type="range"] {
width: 100%;
margin: 10px 0;
}
label {
font-weight: bold;
color: #333;
}
@media (max-width: 768px) {
.random-color-generator-container {
flex-direction: column;
}
.hex-color-container, .rgb-color-container {
min-height: 50vh;
}
}
</style>
</head>
<body>
<div class="random-color-generator-container">
<div class="hex-color-container">
<p class="hex-color-value">#ffffff</p>
<button class="hex-btn">Create Hex Color</button>
<button class="hex-copy-color">Copy To Clipboard</button>
</div>
<div class="rgb-color-container">
<p class="rgb-color-value">rgb(255,255,255)</p>
<div>
<label for="red">Red</label>
<input type="range" min="0" max="255" value="0" id="red" />
</div>
<div>
<label for="green">Green</label>
<input type="range" min="0" max="255" value="0" id="green" />
</div>
<div>
<label for="blue">Blue</label>
<input type="range" min="0" max="255" value="0" id="blue" />
</div>
<button class="rgb-btn">Create RGB Color</button>
<button class="rgb-copy-color">Copy To Clipboard</button>
</div>
</div>
<script>
const hexBtn = document.querySelector(".hex-btn");
const hexColorValue = document.querySelector(".hex-color-value");
const hexColorContainer = document.querySelector(".hex-color-container");
const hexCopyBtn = document.querySelector(".hex-copy-color");
// Create Random HEX color
hexBtn.addEventListener("click", () => {
let characterSet = "0123456789ABCDEF";
let hexColorOutput = "";
for (let i = 0, charSetLength = characterSet.length; i < 6; ++i) {
hexColorOutput += characterSet.charAt(
Math.floor(Math.random() * charSetLength)
);
}
hexColorValue.textContent = `#${hexColorOutput}`;
hexColorContainer.style.backgroundColor = `#${hexColorOutput}`;
hexBtn.style.color = `#${hexColorOutput}`;
});
// RGB Color generator
const rgbBtn = document.querySelector(".rgb-btn");
const getRedInputRange = document.querySelector("#red");
const getGreenInputRange = document.querySelector("#green");
const getBlueInputRange = document.querySelector("#blue");
const rgbColorContainer = document.querySelector(".rgb-color-container");
const rgbCopyBtn = document.querySelector(".rgb-copy-color");
const rgbColorValue = document.querySelector(".rgb-color-value");
rgbBtn.addEventListener("click", updateRGBColor);
getRedInputRange.addEventListener("input", updateRGBColor);
getGreenInputRange.addEventListener("input", updateRGBColor);
getBlueInputRange.addEventListener("input", updateRGBColor);
function updateRGBColor() {
let extractRedValue = getRedInputRange.value;
let extractGreenValue = getGreenInputRange.value;
let extractBlueValue = getBlueInputRange.value;
rgbColorValue.textContent = `rgb(${extractRedValue}, ${extractGreenValue}, ${extractBlueValue})`;
rgbColorContainer.style.backgroundColor = `rgb(${extractRedValue}, ${extractGreenValue}, ${extractBlueValue})`;
rgbBtn.style.color = `rgb(${extractRedValue}, ${extractGreenValue}, ${extractBlueValue})`;
}
function copyHexColorToClipBoard() {
navigator.clipboard.writeText(hexColorValue.textContent);
alert("Hex Color is copied to clipboard");
}
hexCopyBtn.addEventListener("click", copyHexColorToClipBoard);
function copyRgbColorToClipboard() {
navigator.clipboard.writeText(rgbColorValue.textContent);
alert("RGB Color is copied to clipboard");
}
rgbCopyBtn.addEventListener("click", copyRgbColorToClipboard);
// Initialize with random colors
hexBtn.click();
updateRGBColor();
</script>
</body>
</html>