Sure! Below is a complete HTML script using Tailwind CSS v3 that creates a stylish website with the features you requested:
- Snowy Background: An animated snowfall effect using CSS.
- PC Monitor Display: A stylized PC monitor that displays neon text.
- Text Input Functionality: Allows you to enter text via your keyboard, displaying each line in the monitor upon pressing the
Enter key.
Step-by-Step Implementation
1. Setting Up Tailwind CSS
We'll use the Tailwind CSS CDN for quick integration. This allows us to utilize Tailwind's utility classes without any build setup.
2. Creating the Snowy Background
We'll create a snowfall effect using pure CSS animations. Multiple div elements will represent snowflakes, each animated to fall from the top to the bottom of the screen.
3. Designing the PC Monitor
A div will represent the PC monitor with a frame. Inside it, another div will act as the screen displaying the neon text.
4. Handling User Input
An invisible textarea will capture user input. JavaScript will listen for the Enter keypress to append the entered text to the monitor's display, creating a new line each time.
Complete Code
Here's the complete HTML, CSS, and JavaScript code. You can copy and paste this into an index.html file and open it in your browser to see it in action.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Stylish PC Monitor with Snowy Background</title>
<!-- Tailwind CSS CDN -->
<script src="https://cdn.tailwindcss.com"></script>
<style>
/* Snowflake styles */
.snowflake {
position: fixed;
top: -10px;
width: 10px;
height: 10px;
background: white;
opacity: 0.8;
border-radius: 50%;
pointer-events: none;
animation: fall linear infinite;
}
/* Keyframes for snowfall */
@keyframes fall {
to {
transform: translateY(110vh) rotate(360deg);
opacity: 0;
}
}
/* Neon Text Effects */
.neon-text {
color: #39ff14;
text-shadow:
0 0 5px #39ff14,
0 0 10px #39ff14,
0 0 20px #39ff14,
0 0 40px #39ff14,
0 0 80px #39ff14;
}
/* PC Monitor Styles */
.monitor {
width: 600px;
height: 400px;
background: #333;
border: 16px solid #555;
border-radius: 8px;
position: relative;
box-shadow: 0 0 20px rgba(0,0,0,0.5);
}
.monitor::before {
content: '';
position: absolute;
top: -32px;
left: 50%;
transform: translateX(-50%);
width: 60px;
height: 20px;
background: #555;
border-radius: 4px;
}
.screen {
width: 100%;
height: 100%;
background: #000;
overflow-y: auto;
padding: 20px;
box-sizing: border-box;
}
/* Hide the textarea */
#inputArea {
position: absolute;
opacity: 0;
height: 0;
width: 0;
}
</style>
</head>
<body class="bg-gray-900 relative overflow-hidden min-h-screen flex items-center justify-center">
<!-- Snowflakes -->
<div id="snowContainer" class="fixed inset-0 pointer-events-none"></div>
<!-- PC Monitor -->
<div class="monitor flex flex-col items-center justify-center">
<div id="screen" class="screen neon-text text-lg font-mono"></div>
</div>
<!-- Hidden Textarea for Input -->
<textarea id="inputArea" autofocus></textarea>
<script>
// Function to create snowflakes
function createSnowflakes(count) {
const snowContainer = document.getElementById('snowContainer');
for(let i = 0; i < count; i++) {
const snowflake = document.createElement('div');
snowflake.classList.add('snowflake');
snowflake.style.left = Math.random() * 100 + 'vw';
snowflake.style.animationDuration = (5 + Math.random() * 10) + 's';
snowflake.style.width = snowflake.style.height = (2 + Math.random() * 8) + 'px';
snowContainer.appendChild(snowflake);
}
}
// Initialize snowflakes
createSnowflakes(100);
// Handle user input
const inputArea = document.getElementById('inputArea');
const screen = document.getElementById('screen');
// Focus on the hidden textarea when the page loads
window.onload = () => {
inputArea.focus();
};
inputArea.addEventListener('keydown', function(event) {
if (event.key === 'Enter') {
event.preventDefault();
const text = inputArea.value.trim();
if(text !== '') {
const newLine = document.createElement('div');
newLine.textContent = text;
screen.appendChild(newLine);
inputArea.value = '';
// Scroll to the bottom of the screen
screen.scrollTop = screen.scrollHeight;
}
}
});
// Optional: Click anywhere to focus on the textarea
document.body.addEventListener('click', () => {
inputArea.focus();
});
</script>
</body>
</html>
Explanation of the Code
1. Snowy Background
- HTML: A
div with the ID snowContainer is added to hold all the snowflake elements.
- CSS: The
.snowflake class styles each snowflake as a small white circle with a falling animation defined by the @keyframes fall. The animation makes snowflakes fall from the top to the bottom of the viewport while rotating.
- JavaScript: The
createSnowflakes function generates a specified number of snowflakes, randomizing their position, size, and falling speed to create a natural snowfall effect.
2. PC Monitor Design
- HTML: A
div with the class monitor represents the PC monitor. Inside it, another div with the ID screen displays the entered neon text.
- CSS: The
.monitor class styles the monitor with a dark background, borders to mimic the frame, and a pseudo-element ::before to represent the monitor's stand. The .screen class styles the display area with a black background and enables scrolling if the content overflows.
- Neon Effect: The
.neon-text class applies bright green color and multiple text shadows to create a glowing neon effect.
3. Handling User Input
- HTML: A hidden
textarea with the ID inputArea captures user input. It's hidden from view but still focuses to receive keyboard events.
- JavaScript:
- The
inputArea is automatically focused when the page loads and whenever the user clicks anywhere on the page, ensuring it captures all keyboard input.
- An event listener for the
keydown event detects when the Enter key is pressed.
- Upon pressing
Enter, the script prevents the default behavior, retrieves the entered text, appends it as a new div inside the screen area, clears the textarea, and scrolls the screen to show the latest entry.
Customization
- Snowflake Count: Adjust the number passed to
createSnowflakes(100); to increase or decrease the number of snowflakes.
- Neon Text Color: Change the color in the
.neon-text class (currently #39ff14) to any other color to customize the neon effect.
- Monitor Size: Modify the
width and height in the .monitor class to resize the PC monitor.
Final Notes
This implementation provides a stylish and interactive web page that responds to your keyboard input, displaying neon text within a PC monitor graphic against a snowy backdrop. Feel free to further enhance the design or functionality as per your requirements!