Skip to content

Instantly share code, notes, and snippets.

@muxueqz
Created August 28, 2024 17:29
Show Gist options
  • Save muxueqz/4f355b4aa15d270ca0b25e4c61d79ffd to your computer and use it in GitHub Desktop.
Save muxueqz/4f355b4aa15d270ca0b25e4c61d79ffd to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Color Buttons</title>
<style>
.color-button {
width: 50px;
height: 50px;
border: none;
margin: 5px;
cursor: pointer;
}
#colorContainer {
margin-top: 20px;
}
</style>
</head>
<body>
<h1>Enter RGBA or Hex Colors</h1>
<textarea id="colorInput" placeholder="Enter colors separated by commas, e.g., rgba(255,0,0,1), #00ff00"></textarea>
<button onclick="createColorButtons()">Create Buttons</button>
<div id="colorContainer"></div>
<script>
function createColorButtons() {
const colorContainer = document.getElementById('colorContainer');
colorContainer.innerHTML = ''; // Clear previous buttons
const colors = document.getElementById('colorInput').value.split(',');
colors.forEach(color => {
color = color.trim();
if (color) {
const button = document.createElement('button');
button.className = 'color-button';
button.style.backgroundColor = color;
button.title = color; // Show color code on hover
colorContainer.appendChild(button);
}
});
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment