09 Mayıs 2025, 00:35
#1 Çevrimdışı
Kullanıcıların profil bilgileri misafirlere kapatılmıştır.
Html/CSS/Js ile Rastgele Renk Üretici (Random Color Generator)
Merhabalar arkadaşlar Html css ve
js ile rastgele renk üretici kod yazıp paylaşmak istedim umarım faydalı olur
Kod: Kodu kopyalamak için üzerine çift tıklayın!
<!DOCTYPE html>
<html lang="tr">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Rastgele Renk Üretici</title>
<style>
body {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
font-family: Arial, sans-serif;
transition: background-color 0.3s ease;
}
#colorCode {
font-size: 24px;
margin-bottom: 20px;
}
button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
border: none;
background-color: #333;
color: white;
border-radius: 5px;
}
</style>
</head>
<body>
<div id="colorCode">#FFFFFF</div>
<button onclick="changeColor()">Renk Değiştir</button>
<script>
function getRandomColor() {
const letters = "0123456789ABCDEF";
let color = "#";
for (let i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}
function changeColor() {
const newColor = getRandomColor();
document.body.style.backgroundColor = newColor;
document.getElementById("colorCode").textContent = newColor;
}
</script>
</body>
</html>