HTML和CSS来设计聊天对话框的外观和布局的代码
时间: 2024-02-24 18:55:55 浏览: 108
聊天室设计代码
5星 · 资源好评率100%
下面是一个简单的HTML和CSS代码示例,用于设计聊天对话框的外观和布局:
```html
<!DOCTYPE html>
<html>
<head>
<title>Chat Dialog</title>
<style type="text/css">
body {
font-family: Arial, sans-serif;
background-color: #f5f5f5;
margin: 0;
padding: 0;
}
.chat-box {
width: 400px;
height: 500px;
margin: 50px auto;
background-color: #fff;
border-radius: 5px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.3);
overflow: hidden;
}
.chat-header {
height: 50px;
background-color: #4caf50;
color: #fff;
display: flex;
align-items: center;
padding: 0 15px;
}
.chat-header h2 {
margin: 0;
font-size: 20px;
font-weight: normal;
}
.chat-body {
height: 400px;
overflow-y: scroll;
padding: 15px;
}
.chat-message {
margin: 10px 0;
display: flex;
flex-direction: column;
max-width: 60%;
align-self: flex-end;
padding: 10px;
background-color: #e1ffc7;
border-radius: 5px;
}
.chat-message p {
margin: 0;
font-size: 14px;
line-height: 1.4;
}
.chat-message .time {
font-size: 12px;
color: #999;
text-align: right;
margin-top: 5px;
}
.chat-input {
display: flex;
align-items: center;
padding: 10px;
background-color: #f0f0f0;
}
.chat-input input[type="text"] {
flex: 1;
border: none;
padding: 8px;
border-radius: 5px;
font-size: 14px;
}
.chat-input input[type="submit"] {
background-color: #4caf50;
color: #fff;
border: none;
padding: 8px 15px;
border-radius: 5px;
margin-left: 10px;
font-size: 14px;
cursor: pointer;
}
</style>
</head>
<body>
<div class="chat-box">
<div class="chat-header">
<h2>Chat Dialog</h2>
</div>
<div class="chat-body">
<div class="chat-message">
<p>Hello!</p>
<div class="time">11:30 AM</div>
</div>
<div class="chat-message">
<p>How are you?</p>
<div class="time">11:31 AM</div>
</div>
<div class="chat-message">
<p>I'm fine, thanks.</p>
<div class="time">11:32 AM</div>
</div>
</div>
<div class="chat-input">
<input type="text" placeholder="Type your message here...">
<input type="submit" value="Send">
</div>
</div>
</body>
</html>
```
这个代码会生成一个类似于聊天对话框的界面,包括一个标题栏、消息列表和输入框。您可以根据需求进行修改和优化。
阅读全文