Add a touch of futurism to your website or blog with this stunning 3D digital clock. Using HTML, CSS, and JavaScript, we'll create a fully functional clock that displays the current time, date, and day of the week. Get ready to impress your visitors with this sleek and modern design.
Code:
HTML
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>3D Digital Clock</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="clock-container">
<div class="clock-3d">
<h1 id="clock"></h1>
<p id="date"></p>
<p id="day"></p>
</div>
<p>Created by <a href="https://codecrafti.blogspot.com/">CodeCrafti</a></p>
</div>
<script src="script.js"></script>
</body>
</html>
CSS (in style.css file)
background-color: #2b2b2b;
font-family: Arial, sans-serif;
}
.clock-container {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
perspective: 1000px;
text-align: center;
}
.clock-3d {
transform: rotateX(-20deg) rotateY(-20deg);
transform-style: preserve-3d;
}
#clock {
font-size: 64px;
font-weight: bold;
color: #66cc00;
text-shadow: 0 0 10px rgba(0, 255, 0, 0.5);
}
#date {
font-size: 24px;
color: #33cc33;
}
#day {
font-size: 24px;
color: #33cc33;
text-transform: uppercase;
}
.clock-3d::before {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: linear-gradient(to bottom, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0));
opacity: 0.5;
z-index: -1;
}
a {
color: #66cc00;
text-decoration: none;
}
a:hover {
color: #33cc33;
}
JavaScript (in script.js file)
JavaScriptfunction updateClock() {
const now = new Date();
const hours = now.getHours().toString().padStart(2, '0');
const minutes = now.getMinutes().toString().padStart(2, '0');
const seconds = now.getSeconds().toString().padStart(2, '0');
const day = now.getDate().toString().padStart(2, '0');
const months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
const month = months[now.getMonth()];
const year = now.getFullYear();
const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
const currentDay = days[now.getDay()];
document.getElementById('clock').textContent = `${hours}:${minutes}:${seconds}`;
document.getElementById('date').textContent = `${day} ${month} ${year}`;
document.getElementById('day').textContent = currentDay;
}
updateClock();
setInterval(updateClock, 1000);
Explanation:
This code uses HTML to create the basic structure, CSS for styling and 3D effects, and JavaScript to update the clock in real-time.
Tips and Variations:
Adjust the perspective
and transform
values to change the 3D effect.
Modify the text-shadow
property to change the clock text's appearance.
Experiment with different gradient colors and orientations for the background.
Add more complex animations or effects using CSS keyframes or JavaScript libraries.
Conclusion:
With this code, you've created a stunning 3D digital clock that's sure to impress your website visitors. Feel free to customize and experiment with different styles and effects.Live Demo
0 Comments