Certainly! Below is a complete HTML example using Tailwind CSS v3 that creates a stylish website with:
- A Creative Background: Featuring a vibrant gradient with animated elements.
- A PC Monitor Component: Displaying neon-style text that updates based on user keyboard input.
Features Overview
- Creative Background: Utilizes a gradient background with an animated moving gradient effect for visual appeal.
- PC Monitor Design: A stylized PC monitor created with div elements, including a screen area.
- Neon Text Display: Captures user input via a hidden text input and displays it inside the monitor with a neon glow effect.
Implementation Steps
- Setup Tailwind CSS: Included via CDN for ease of use.
- HTML Structure: Organized to include the background, monitor, and hidden input.
- Tailwind Styling: Utilizes utility classes for layout, styling, and animations.
- JavaScript Functionality: Listens for keyboard input and updates the neon text accordingly.
Complete HTML Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Stylish PC Monitor with Neon Text</title>
<!-- Tailwind CSS v3 CDN -->
<script src="https://cdn.tailwindcss.com"></script>
<style>
/* Custom animation for background */
@keyframes gradientMove {
0% { background-position: 0% 50%; }
50% { background-position: 100% 50%; }
100% { background-position: 0% 50%; }
}
/* Neon glow effect */
.text-neon {
color: #39FF14;
text-shadow:
0 0 5px #39FF14,
0 0 10px #39FF14,
0 0 20px #39FF14,
0 0 40px #39FF14,
0 0 80px #39FF14;
}
/* Prevent text selection for better UX */
body, html {
user-select: none;
}
</style>
</head>
<body class="min-h-screen flex items-center justify-center bg-gradient-to-r from-purple-400 via-pink-500 to-red-500 animate-gradientMove"
style="background-size: 400% 400%; animation: gradientMove 15s ease infinite;">
<!-- PC Monitor Container -->
<div class="flex flex-col items-center">
<!-- Monitor Frame -->
<div class="w-80 h-60 bg-black rounded-lg shadow-2xl border-4 border-gray-800 flex flex-col items-center justify-center relative">
<!-- Monitor Screen -->
<div class="w-11/12 h-5/6 bg-gray-900 rounded-md overflow-hidden flex items-center justify-center">
<div id="neonText" class="text-neon text-lg break-words text-center px-2">
Type something...
</div>
</div>
<!-- Monitor Stand -->
<div class="w-16 h-4 bg-gray-800 rounded-b-full mt-2"></div>
</div>
<!-- Hidden Input to Capture Keyboard Events -->
<input type="text" id="hiddenInput" class="opacity-0 absolute" autofocus>
<!-- Instruction Text -->
<p class="mt-4 text-white text-sm">Start typing to display text inside the monitor!</p>
</div>
<!-- JavaScript to Handle Keyboard Input -->
<script>
const hiddenInput = document.getElementById('hiddenInput');
const neonText = document.getElementById('neonText');
// Focus the hidden input on page load
window.onload = () => {
hiddenInput.focus();
};
// Listen for input events
hiddenInput.addEventListener('input', (e) => {
neonText.textContent = e.target.value || 'Type something...';
});
// Optional: Prevent scrolling when using arrow keys or space
window.addEventListener('keydown', function(e) {
// Keys you want to prevent default behavior
const keys = ['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'Space'];
if (keys.includes(e.key)) {
e.preventDefault();
}
});
</script>
</body>
</html>
Explanation of the Code
-
Tailwind CSS Integration:
- Included via CDN for quick setup.
- Custom styles added within
<style> tags for animations and neon effects that aren't directly achievable with Tailwind utility classes.
-
Background Design:
- Utilizes a
bg-gradient-to-r class with colors transitioning from purple to red.
- An animation
gradientMove smoothly shifts the background colors to create a dynamic effect.
-
PC Monitor Component:
- A
div with fixed width and height (w-80 h-60) to represent the monitor frame.
- Styled with
bg-black, rounded corners, shadows, and borders to mimic a real monitor.
- Inside the frame, another
div acts as the screen, with a dark background (bg-gray-900) and rounded corners.
- The neon text is placed within the screen area, centered both vertically and horizontally.
-
Neon Text Styling:
- The
text-neon class applies a bright green color with multiple layers of text-shadow to create a glowing effect.
- The text updates in real-time based on user input.
-
User Input Handling:
- A hidden text input (
#hiddenInput) captures keyboard input.
- The input is kept invisible and focused by default to ensure seamless typing experience.
- As the user types, the JavaScript event listener updates the
#neonText content.
-
JavaScript Functionality:
- On page load, the hidden input is focused so the user can start typing immediately.
- The
input event listener ensures that any change in the input updates the neon text display.
- Additional event listeners prevent the default scrolling behavior for certain keys, enhancing the typing experience within the monitor.
-
Accessibility and UX Enhancements:
- The
user-select: none style prevents text from being accidentally selected during typing.
- Instructional text guides the user on how to interact with the page.
Customization Tips
Final Thoughts
This example leverages Tailwind CSS's utility-first approach combined with custom CSS for effects that require more control. The setup ensures a modern, visually appealing design while maintaining simplicity and responsiveness. Feel free to expand upon this foundation to add more features, such as additional interactive elements or more complex animations.