You need to enable JavaScript to run this app. Streamlabs Chat如何实现徽章、用户名与消息的对齐布局
优惠活动
大模型
产品
解决方案
定价
更多

Streamlabs Chat如何实现徽章、用户名与消息的对齐布局

Streamlabs Chat 徽章/用户名/消息对齐布局优化

正在为Streamlabs Chat开发布局功能,核心目标是实现徽章、用户名、聊天消息三者的垂直对齐效果。当前基础功能已完成开发,但实际展示效果与预期目标存在偏差:

  • 现有实现的元素排布没有达到参考标准
  • 目标效果为徽章、用户名、聊天消息沿统一基线对齐,无错位、偏移问题

刚性调整约束:当用户没有携带任何徽章时,用户名必须从容器最左侧起始,不能预留空白间隙。现有代码已经实现了该特性,调整过程中绝对不能破坏该逻辑。

现有代码

聊天项HTML模板

<!-- chat item -->
<script type="text/template" id="chatlist_item">
  <div data-from="{from}" data-id="{messageId}">
    <span class="meta" style="color: {color}">
      <span class="badges"></span>
      <span class="name">{from}</span>
      <span class="message">{message}</span>
    </span>
  </div>
</script>

页面样式CSS

@import url(https://fonts.googleapis.com/css?family=Roboto:700);

* {
    box-sizing: border-box;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    text-shadow: 0 0 1px #000, 0 0 2px #000;
    background: {background_color};
    font-family: 'Roboto';
    font-weight: 700;
    font-size: {font_size};
    line-height: 1.5em;
    color: {text_color};
}

#log>div {
    animation: fadeInRight .3s ease forwards, fadeOut 0.5s ease {message_hide_delay} forwards;
    -webkit-animation: fadeInRight .3s ease forwards, fadeOut 0.5s ease {message_hide_delay} forwards;
}

.colon {
    display: none;
}

#log {
    display: table;
    position: absolute;
    bottom: 0;
    left: 0;
    padding: 0 10px 10px;
    width: 100%;
    table-layout: fixed;
}

#log>div {
    display: table-row;
}

#log>div.deleted {
    visibility: hidden;
}

#log .emote {
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    padding: 0.4em 0.2em;
    position: relative;
}

#log .emote img {
    display: inline-block;
    height: 1em;
    opacity: 0;
}

#log .message, #log .meta {
    vertical-align: top;
    display: table-cell;
    padding-bottom: 0.1em;
    margin-left: 0.2em;
}

#log .meta {
    width: 35%;
    text-align: left;
    padding-right: 0.5em;
    white-space: nowrap;
    text-overflow: clip;
    overflow: hidden;
}

#log .message {
    word-wrap: break-word;
    white-space: initial;
    width: 65%;
    display: inline-block;
    color: #fff;
}

.badge {
    display: inline-block;
    margin-right: 0.2em;
    position: relative;
    height: 1em;
    vertical-align: middle;
    top: -0.1em;
}

.name {
    margin-left: 0.2em;
}

当前需要排查代码中缺失的配置项,解决布局对齐偏差问题,落地预期的展示效果。


内容的提问来源于stack exchange,提问作者infernalx

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.11.13 07:15:02