css - 如何使用CSS根据用户ID设置聊天框

标签 css chat

我正在开发聊天应用程序。我需要显示输入消息的用户名 我需要在聊天框中显示消息和用户 ID。

如果此时用户输入单个字母,我需要向用户显示我需要显示的长度。但我无法显示去外面的用户 ID

.t {
  position: relative;
  background: white;
  text-align: right;
      padding-top: 18px;
    padding-bottom: 7px;
    padding-left: 7px;
    padding-right: 7px;
  border-radius: 6px;
  border: 1px solid #ccc;
  float: right;
  font-size: 12px;
     margin-bottom: 7px;
    margin-right: 4px;
    margin-left: 4px;
}

.t::before {
  content: '';
  position: absolute;
  visibility: visible;
  top: -1px;
  right: -10px;
  border: 10px solid transparent;
  border-top: 10px solid #ccc;
}

.t::after {
  content: '';
  position: absolute;
  visibility: visible;
  top: 0px;
  right: -8px;
  border: 10px solid transparent;
  border-top: 10px solid white;
  clear: both;
  
}

.t {
  clear: right;
}

.t img {
	display: block;
	height: auto;
	max-width: 100%;
}
.t .username {
  position: absolute;
  font-weight: bold;
  font-size: 12px;
  color: #8e0035;
  top: 4px;
  right: 10px;
}


.t .message{
   word-break: break-all;
}
<div class="t">
  <span class="username">kranthi</span>
  <span class="message">This is a very long message, as you can see it will be placed in multiple lines..This is a very long message, as you can see it will be placed in multiple lines.</span>
</div>

<div class="t">
  <span class="username">kranthi</span>
  <span class="message">thanks</span>
</div>

<div class="t">
  <span class="username">27535635496</span>
  <span class="message">1</span>
</div>

enter image description here

最佳答案

您必须将绝对位置更改为相对于用户名类的位置,然后向其添加显示 block ,以便消息显示在 id 下。同时删除 top 和 right 属性:

.t .username {
  position: relative;
  display: block;
  font-weight: bold;
  font-size: 12px;
  color: #8e0035;
}

关于css - 如何使用CSS根据用户ID设置聊天框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37924479/

相关文章:

php - fatal error : Uncaught TypeError: Cannot access offset of type string on string

c++ - 两台具有相同 IP 地址的计算机 - 使用套接字的聊天应用程序

html - 针对特定的 <div> CSS

html - SCSS - 从一组样式中排除指定的容器

CSS Flexbox 和响应式设计 : Converting 3 columns into 2 rows

html - div定位不正确

python - 用于网络聊天应用程序的 django 和 ejabberd 之间的交互

php - 如何在html页面上制作常量脚本

javascript - 聊天 react 中的消息顺序

ruby-on-rails - websocket-rails 聊天室