Spaces:
Running
Running
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Modern Chat Interface</title> | |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"> | |
<style> | |
* { | |
margin: 0; | |
padding: 0; | |
box-sizing: border-box; | |
font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; | |
} | |
:root { | |
--primary: #4361ee; | |
--primary-light: #4895ef; | |
--secondary: #3f37c9; | |
--success: #4cc9f0; | |
--dark: #1d3557; | |
--light: #f8f9fa; | |
--gray: #6c757d; | |
--light-gray: #e9ecef; | |
--border-radius: 16px; | |
--shadow: 0 4px 12px rgba(0, 0, 0, 0.08); | |
--transition: all 0.3s ease; | |
} | |
body { | |
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); | |
height: 100vh; | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
padding: 20px; | |
} | |
.chat-container { | |
width: 100%; | |
max-width: 900px; | |
height: 90vh; | |
background: white; | |
border-radius: var(--border-radius); | |
display: flex; | |
flex-direction: column; | |
overflow: hidden; | |
box-shadow: var(--shadow); | |
} | |
.chat-header { | |
background: var(--primary); | |
color: white; | |
padding: 20px; | |
display: flex; | |
align-items: center; | |
gap: 15px; | |
box-shadow: 0 2px 8px rgba(67, 97, 238, 0.3); | |
} | |
.avatar { | |
width: 45px; | |
height: 45px; | |
border-radius: 50%; | |
background: var(--success); | |
display: flex; | |
align-items: center; | |
justify-content: center; | |
font-weight: bold; | |
font-size: 18px; | |
} | |
.chat-header-info h2 { | |
font-weight: 600; | |
font-size: 1.3rem; | |
} | |
.chat-header-info p { | |
font-size: 0.85rem; | |
opacity: 0.9; | |
margin-top: 4px; | |
} | |
.chat-messages { | |
flex: 1; | |
padding: 20px; | |
overflow-y: auto; | |
background: var(--light); | |
display: flex; | |
flex-direction: column; | |
gap: 15px; | |
} | |
.message { | |
max-width: 70%; | |
padding: 12px 16px; | |
border-radius: var(--border-radius); | |
position: relative; | |
animation: fadeIn 0.3s ease; | |
line-height: 1.4; | |
box-shadow: var(--shadow); | |
} | |
@keyframes fadeIn { | |
from { opacity: 0; transform: translateY(10px); } | |
to { opacity: 1; transform: translateY(0); } | |
} | |
.received { | |
align-self: flex-start; | |
background: white; | |
border-bottom-left-radius: 4px; | |
} | |
.sent { | |
align-self: flex-end; | |
background: var(--primary-light); | |
color: white; | |
border-bottom-right-radius: 4px; | |
} | |
.message-time { | |
font-size: 0.7rem; | |
opacity: 0.7; | |
margin-top: 8px; | |
display: block; | |
} | |
.sent .message-time { | |
color: rgba(255, 255, 255, 0.8); | |
text-align: right; | |
} | |
.received .message-time { | |
color: var(--gray); | |
} | |
.chat-input-area { | |
padding: 15px; | |
background: white; | |
border-top: 1px solid var(--light-gray); | |
display: flex; | |
gap: 10px; | |
} | |
.chat-input { | |
flex: 1; | |
padding: 15px 20px; | |
border: 2px solid var(--light-gray); | |
border-radius: 30px; | |
font-size: 1rem; | |
outline: none; | |
transition: var(--transition); | |
} | |
.chat-input:focus { | |
border-color: var(--primary-light); | |
box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.2); | |
} | |
.send-button { | |
width: 50px; | |
height: 50px; | |
border-radius: 50%; | |
background: var(--primary); | |
color: white; | |
border: none; | |
cursor: pointer; | |
display: flex; | |
align-items: center; | |
justify-content: center; | |
font-size: 18px; | |
transition: var(--transition); | |
box-shadow: var(--shadow); | |
} | |
.send-button:hover { | |
background: var(--secondary); | |
transform: translateY(-2px); | |
} | |
.send-button:active { | |
transform: translateY(0); | |
} | |
.status-indicator { | |
display: inline-block; | |
width: 8px; | |
height: 8px; | |
border-radius: 50%; | |
background: #20bf6b; | |
margin-left: 8px; | |
} | |
/* Responsive design */ | |
@media (max-width: 768px) { | |
.chat-container { | |
height: 95vh; | |
border-radius: 12px; | |
} | |
.message { | |
max-width: 85%; | |
} | |
.chat-header { | |
padding: 15px; | |
} | |
.chat-input-area { | |
padding: 12px; | |
} | |
.chat-input { | |
padding: 12px 16px; | |
} | |
.send-button { | |
width: 45px; | |
height: 45px; | |
} | |
} | |
@media (max-width: 480px) { | |
body { | |
padding: 10px; | |
} | |
.chat-container { | |
height: 100vh; | |
border-radius: 0; | |
} | |
.chat-header { | |
padding: 12px; | |
} | |
.avatar { | |
width: 35px; | |
height: 35px; | |
font-size: 14px; | |
} | |
.chat-header-info h2 { | |
font-size: 1.1rem; | |
} | |
.chat-header-info p { | |
font-size: 0.75rem; | |
} | |
.chat-messages { | |
padding: 15px 10px; | |
} | |
.message { | |
max-width: 90%; | |
padding: 10px 14px; | |
font-size: 0.9rem; | |
} | |
.chat-input-area { | |
padding: 10px; | |
} | |
.send-button { | |
width: 40px; | |
height: 40px; | |
font-size: 16px; | |
} | |
} | |
/* Scrollbar styling */ | |
.chat-messages::-webkit-scrollbar { | |
width: 6px; | |
} | |
.chat-messages::-webkit-scrollbar-track { | |
background: var(--light-gray); | |
border-radius: 3px; | |
} | |
.chat-messages::-webkit-scrollbar-thumb { | |
background: var(--gray); | |
border-radius: 3px; | |
} | |
.chat-messages::-webkit-scrollbar-thumb:hover { | |
background: var(--dark); | |
} | |
</style> | |
</head> | |
<body> | |
<div class="chat-container"> | |
<div class="chat-header"> | |
<div class="avatar">JD</div> | |
<div class="chat-header-info"> | |
<h2>John Doe <span class="status-indicator"></span></h2> | |
<p>Online - Last seen just now</p> | |
</div> | |
</div> | |
<div class="chat-messages" id="chat-messages"> | |
<div class="message received"> | |
Hey there! How's your day going? | |
<span class="message-time">10:02 AM</span> | |
</div> | |
<div class="message sent"> | |
Hi! It's going great, thanks for asking. How about yours? | |
<span class="message-time">10:03 AM</span> | |
</div> | |
<div class="message received"> | |
Can't complain! Just working on some new projects. | |
<span class="message-time">10:05 AM</span> | |
</div> | |
<div class="message sent"> | |
That sounds exciting! What kind of projects? | |
<span class="message-time">10:06 AM</span> | |
</div> | |
<div class="message received"> | |
I'm building a new chat interface with modern CSS. It's coming along nicely! | |
<span class="message-time">10:08 AM</span> | |
</div> | |
<div class="message sent"> | |
Nice! I love how clean and responsive this chat looks. The design is really modern. | |
<span class="message-time">10:10 AM</span> | |
</div> | |
<div class="message received"> | |
Thanks! I used flexbox and some smooth animations to make it feel alive. | |
<span class="message-time">10:12 AM</span> | |
</div> | |
</div> | |
<div class="chat-input-area"> | |
<input | |
type="text" | |
class="chat-input" | |
id="message-input" | |
placeholder="Type your message here..." | |
autocomplete="off" | |
> | |
<button class="send-button" id="send-button"> | |
<i class="fas fa-paper-plane"></i> | |
</button> | |
</div> | |
</div> | |
<script> | |
document.addEventListener('DOMContentLoaded', () => { | |
const chatMessages = document.getElementById('chat-messages'); | |
const messageInput = document.getElementById('message-input'); | |
const sendButton = document.getElementById('send-button'); | |
// Function to add a new message | |
function addMessage(text, isSent) { | |
if (!text.trim()) return; | |
const messageDiv = document.createElement('div'); | |
messageDiv.classList.add('message'); | |
messageDiv.classList.add(isSent ? 'sent' : 'received'); | |
const now = new Date(); | |
const timeString = now.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }); | |
messageDiv.innerHTML = ` | |
${text} | |
<span class="message-time">${timeString}</span> | |
`; | |
chatMessages.appendChild(messageDiv); | |
// Scroll to bottom | |
chatMessages.scrollTop = chatMessages.scrollHeight; | |
// Clear input | |
messageInput.value = ''; | |
} | |
// Send message on button click | |
sendButton.addEventListener('click', () => { | |
addMessage(messageInput.value, true); | |
}); | |
// Send message on Enter key (but not Shift+Enter) | |
messageInput.addEventListener('keydown', (e) => { | |
if (e.key === 'Enter' && !e.shiftKey) { | |
e.preventDefault(); | |
addMessage(messageInput.value, true); | |
} | |
}); | |
// Auto-scroll to bottom on load | |
chatMessages.scrollTop = chatMessages.scrollHeight; | |
// Simulate received messages periodically | |
setInterval(() => { | |
const responses = [ | |
"That's interesting!", | |
"I totally agree with you.", | |
"What do you think about that?", | |
"I'm glad you mentioned it.", | |
"Let me know if you need any help!", | |
"Sounds like a plan!", | |
"I was just thinking the same thing." | |
]; | |
if (Math.random() > 0.7) { | |
const randomResponse = responses[Math.floor(Math.random() * responses.length)]; | |
addMessage(randomResponse, false); | |
} | |
}, 10000); | |
}); | |
</script> | |
</body> | |
</html> |