-
Notifications
You must be signed in to change notification settings - Fork 0
/
html.html
107 lines (103 loc) · 2.79 KB
/
html.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Google Chat App</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
background-color: #f0f0f0;
}
.chat-container {
width: 400px;
border: 1px solid #ccc;
border-radius: 5px;
overflow: hidden;
}
.chat-messages {
height: 300px;
overflow-y: scroll;
padding: 10px;
background-color: #fff;
}
.message {
margin-bottom: 10px;
padding: 8px 12px;
background-color: #f1f1f1;
border-radius: 5px;
}
.message.from-me {
align-self: flex-end;
background-color: #d4eaf0;
}
.message .sender {
font-weight: bold;
color: #333;
}
.message .text {
margin-top: 5px;
color: #333;
}
.chat-input {
width: calc(100% - 24px);
margin: 10px;
padding: 8px 12px;
border: 1px solid #ccc;
border-radius: 5px;
font-size: 14px;
}
.send-button {
width: 100px;
padding: 8px;
margin: 10px;
border: none;
border-radius: 5px;
background-color: #007bff;
color: #fff;
cursor: pointer;
}
</style>
</head>
<body>
<div class="chat-container">
<div class="chat-messages" id="chat-messages">
<!-- Messages will be dynamically added here -->
</div>
<div>
<textarea class="chat-input" id="message-input" placeholder="Type your message..."></textarea>
<button class="send-button" onclick="sendMessage()">Send</button>
</div>
</div>
<script>
function sendMessage() {
const messageInput = document.getElementById('message-input');
const messageText = messageInput.value.trim();
if (messageText === '') return;
const message = createMessage(messageText, true);
const chatMessages = document.getElementById('chat-messages');
chatMessages.appendChild(message);
// Clear the input after sending
messageInput.value = '';
}
function createMessage(text, fromMe) {
const messageDiv = document.createElement('div');
messageDiv.classList.add('message');
if (fromMe) {
messageDiv.classList.add('from-me');
messageDiv.innerHTML = `<span class="sender">Me:</span><div class="text">${text}</div>`;
} else {
messageDiv.innerHTML = `<span class="sender">Someone:</span><div class="text">${text}</div>`;
}
return messageDiv;
}
</script>
</body>
</html>