Streamlabs自定义CSS实现带圆角半透明背景聊天框
实现Streamlabs聊天框半透明圆角背景效果
以下是修改后的CSS代码,可直接替换原有代码实现预期效果:
@import url(https://fonts.googleapis.com/css?family=Roboto:700); * { box-sizing: border-box; } html, body { height: 100%; overflow: hidden; background: transparent; /* 清除平台自带背景干扰 */ } body { text-shadow: 0 0 1px #000, 0 0 2px #000; 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; /* 核心样式:半透明背景+圆角 */ background: rgba(0, 0, 0, 0.5); border-radius: 12px; padding: 8px 12px; margin-bottom: 8px; display: flex; align-items: flex-start; } .colon { display: none; } #log { position: absolute; bottom: 0; left: 0; padding: 0 10px 10px; width: 100%; display: flex; flex-direction: column; } #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 .meta { text-align: right; padding-right: 0.8em; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; flex-shrink: 0; /* 避免用户名被压缩 */ } #log .message { word-wrap: break-word; flex: 1; /* 让消息内容自动填充剩余空间 */ } .badge { display: inline-block; margin-right: 0.2em; position: relative; height: 1em; vertical-align: middle; top: -0.1em; } .name { margin-left: 0.2em; }
关键改动说明
- 清除平台自带背景:将
html, body的background设为transparent,避免默认蓝色背景干扰 - 消息容器样式:给每个聊天消息(
#log>div)添加半透明背景(rgba(0,0,0,0.5))、圆角(border-radius:12px),同时增加内边距和消息间距提升可读性 - 布局优化:改用flex布局调整用户名和消息内容的排版,避免内容挤压
你可以根据需求调整rgba的颜色值(前三个数字)和透明度(第四个数字,范围0-1),以及border-radius的数值改变圆角大小。
内容的提问来源于stack exchange,提问作者Maximilian Freitag
相关产品推荐
相关产品推荐

