可滚动的渐变聊天气泡

huangapple go评论66阅读模式
英文:

Scrollable gradient chat bubbles

问题

我想要一个白色的容器,其中的聊天气泡被掩盖成渐变,当滚动时,它将随下方的渐变而变化,就像这个示例中所示:

可滚动的渐变聊天气泡

我尝试过使.container中位于任何chatBubble后面的部分变为透明,以便.root的背景可见。

.root {
  background-color: linear-gradient(red, yellow);
  width: 100vw;
  height: 100vh;
}

.container {
  width: 100%;
  height: 100vh;
  background-color: white
}

.chatBubble {
  background-color: transparent;
  border-radius: 4px;
  min-width: 50;
  padding: 10px;
}
<div class="root">
  <div class="container">
    <chatBubble>This is a chat bubble</chatBubble>
    <chatBubble>This is another chat bubble</chatBubble>
  </div>
</div>
英文:

I want a white container with chat bubbles masked to a gradient that when scrolled will change with the gradient below, as seen in this example:

可滚动的渐变聊天气泡

I've tried making the part of .container that is behind any chatBubble transparent so that the background of .root is visible.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

.root {
  background-color: linear-gradient(red, yellow);
  width: 100vw;
  height: 100vh;
}

.container {
  width: 100%;
  height: 100vh;
  background-color: white
}

.chatBubble {
  background-color: transparent;
  border-radius: 4px;
  min-width: 50;
  padding: 10px;
}

<!-- language: lang-html -->

&lt;div class=&quot;root&quot;&gt;
  &lt;div class=&quot;container&quot;&gt;
    &lt;chatBubble&gt;This is a chat bubble&lt;/chatBubble&gt;
    &lt;chatBubble&gt;This is another chat bubble&lt;/chatBubble&gt;
  &lt;/div&gt;
&lt;/div&gt;

<!-- end snippet -->

答案1

得分: 2

你可以从 .bubble 中添加 "投影阴影":

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.container {
  --gap: 20px;
  --width: 800px;
  --background: #fff;
  display: flex;
  flex-direction: column;
  max-width: var(--width);
  margin: 16px auto;
  padding: 0 16px;
  overflow: hidden;
  gap: var(--gap);
  box-shadow: 0 0 0 100vw var(--background);
  font-family: sans-serif;
}

.container:before {
  content: '';
  inset: 0;
  position: fixed;
  z-index: -1;
  background: linear-gradient(purple, blue);
}

.bubble {
  max-width: 80%;
  background-color: lightgray;
  border-radius: 16px;
  padding: 8px 16px;
  box-shadow: 0 0 0 var(--gap) var(--background);
  position: relative;
}

.bubble::before,
.bubble::after {
  content: '';
  position: absolute;
  inset: calc(var(--gap) / -2) auto;
  background-color: var(--background);
  width: var(--width);
}

.bubble::before {
  right: 100%;
}

.bubble::after {
  left: 100%;
}

.bubble.primary {
  background-color: transparent;
  color: #fff;
  align-self: flex-end;
}
<div class="container">
  <div class="bubble">show weekend?</div>
  <div class="bubble primary">I'm down!</div>
  <!-- 更多内容 -->
</div>
英文:

You can "drop shadows" from .bubble:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.container {
  --gap: 20px;
  --width: 800px;
  --background: #fff;
  display: flex;
  flex-direction: column;
  max-width: var(--width);
  margin: 16px auto;
  padding: 0 16px;
  overflow: hidden;
  gap: var(--gap);
  box-shadow: 0 0 0 100vw var(--background);
  font-family: sans-serif;
}

.container:before {
  content: &#39;&#39;;
  inset: 0;
  position: fixed;
  z-index: -1;
  background: linear-gradient(purple, blue);
}

.bubble {
  max-width: 80%;
  background-color: lightgray;
  border-radius: 16px;
  padding: 8px 16px;
  box-shadow: 0 0 0 var(--gap) var(--background);
  position: relative;
}

.bubble::before,
.bubble::after {
  content: &#39;&#39;;
  position: absolute;
  inset: calc(var(--gap) / -2) auto;
  background-color: var(--background);
  width: var(--width);
}

.bubble::before {
  right: 100%;
}

.bubble::after {
  left: 100%;
}

.bubble.primary {
  background-color: transparent;
  color: #fff;
  align-self: flex-end;
}

<!-- language: lang-html -->

&lt;div class=&quot;container&quot;&gt;
  &lt;div class=&quot;bubble&quot;&gt;show weekend?&lt;/div&gt;
  &lt;div class=&quot;bubble primary&quot;&gt;I&#39;m down!&lt;/div&gt;
  &lt;div class=&quot;bubble&quot;&gt;lets do this its been way to long since we were all together!&lt;/div&gt;
  &lt;div class=&quot;bubble primary &quot;&gt;Whos down for a pregame&lt;/div&gt;
  &lt;div class=&quot;bubble&quot;&gt;YES! I got the day off! Say when and where?&lt;/div&gt;
  &lt;div class=&quot;bubble primary&quot;&gt;Hows about Old Town at 4? we can get some grub and then head over to the venue&lt;/div&gt;
  &lt;div class=&quot;bubble&quot;&gt;Yeah getting the band back together&lt;/div&gt;
  &lt;div class=&quot;bubble&quot;&gt;show weekend?&lt;/div&gt;
  &lt;div class=&quot;bubble primary&quot;&gt;I&#39;m down!&lt;/div&gt;
  &lt;div class=&quot;bubble&quot;&gt;lets do this its been way to long since we were all together!&lt;/div&gt;
  &lt;div class=&quot;bubble primary &quot;&gt;Whos down for a pregame&lt;/div&gt;
  &lt;div class=&quot;bubble&quot;&gt;YES! I got the day off! Say when and where?&lt;/div&gt;
  &lt;div class=&quot;bubble primary&quot;&gt;Hows about Old Town at 4? we can get some grub and then head over to the venue&lt;/div&gt;
  &lt;div class=&quot;bubble&quot;&gt;Yeah getting the band back together&lt;/div&gt;
  &lt;div class=&quot;bubble&quot;&gt;show weekend?&lt;/div&gt;
  &lt;div class=&quot;bubble primary&quot;&gt;I&#39;m down!&lt;/div&gt;
  &lt;div class=&quot;bubble&quot;&gt;lets do this its been way to long since we were all together!&lt;/div&gt;
  &lt;div class=&quot;bubble primary &quot;&gt;Whos down for a pregame&lt;/div&gt;
  &lt;div class=&quot;bubble&quot;&gt;YES! I got the day off! Say when and where?&lt;/div&gt;
  &lt;div class=&quot;bubble primary&quot;&gt;Hows about Old Town at 4? we can get some grub and then head over to the venue&lt;/div&gt;
  &lt;div class=&quot;bubble&quot;&gt;Yeah getting the band back together&lt;/div&gt;
&lt;/div&gt;

<!-- end snippet -->

答案2

得分: 0

这是我目前的代码,尝试将其遮蔽以便可以使用渐变的白色背景。

html,
body,
.container {
  height: 100%;
}

body {
  margin: 0;
  font-family: system-ui;
}

.container {
  display: flex;
  flex-flow: column nowrap;
  max-width: 60ch;
  margin: auto;
  padding: 1rem;
  background-color: white;
}

.container::before {
  content: '';
  position: fixed;
  inset: 0;
  background: linear-gradient(red, yellow);
}

.bubble {
  z-index: 1;
  min-width: 50px;
  width: fit-content;
  background-color: #eee;
  border-radius: 4px;
  padding: 0.5em;
  margin: 0.2em;
  text-wrap: balance;
}

.bubble.primary {
  color: white;
  background-color: transparent;
  background-blend-mode: multiply;
  align-self: end;
  text-align: end;
}
<div class="container">
  <div class="bubble">show weekend?</div>
  <div class="bubble primary">I'm down!</div>
  <div class="bubble">lets do this its been way to long since we were all together!</div>
  <div class="bubble primary">Whos down for a pregame</div>
  <div class="bubble">YES! I got the day off! Say when and where?</div>
  <div class="bubble primary">Hows about Old Town at 4? we can get some grub and then head over to the venue</div>
  <div class="bubble">Yeah getting the band back together</div>
  <div class="bubble">show weekend?</div>
  <div class="bubble primary">I'm down!</div>
  <div class="bubble">lets do this its been way to long since we were all together!</div>
  <div class="bubble primary">Whos down for a pregame</div>
  <div class="bubble">YES! I got the day off! Say when and where?</div>
  <div class="bubble primary">Hows about Old Town at 4? we can get some grub and then head over to the venue</div>
  <div class="bubble">Yeah getting the band back together</div>
  <div class="bubble">show weekend?</div>
  <div class="bubble primary">I'm down!</div>
  <div class="bubble">lets do this its been way to long since we were all together!</div>
  <div class="bubble primary">Whos down for a pregame</div>
  <div class="bubble">YES! I got the day off! Say when and where?</div>
  <div class="bubble primary">Hows about Old Town at 4? we can get some grub and then head over to the venue</div>
  <div class="bubble">Yeah getting the band back together</div>
</div>
英文:

This is what I've got so far, trying to mask it so I can get the white background to work with the gradient.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

html,
body,
.container {
  height: 100%;
}

body {
  margin: 0;
  font-family: system-ui;
}

.container {
  display: flex;
  flex-flow: column nowrap;
  max-width: 60ch;
  margin: auto;
  padding: 1rem;
  background-color: white;
}

.container::before {
  content: &#39;&#39;;
  position: fixed;
  inset: 0;
  background: linear-gradient(red, yellow);
}

.bubble {
  z-index: 1;
  min-width: 50px;
  width: fit-content;
  background-color: #eee;
  border-radius: 4px;
  padding: 0.5em;
  margin: 0.2em;
  text-wrap: balance;
}

.bubble.primary {
  color: white;
  background-color: transparent;
  background-blend-mode: multiply;
  align-self: end;
  text-align: end;
}

<!-- language: lang-html -->

&lt;div class=&quot;container&quot;&gt;
  &lt;div class=&quot;bubble&quot;&gt;show weekend?&lt;/div&gt;
  &lt;div class=&quot;bubble primary&quot;&gt;I&#39;m down!&lt;/div&gt;
  &lt;div class=&quot;bubble&quot;&gt;lets do this its been way to long since we were all together!&lt;/div&gt;
  &lt;div class=&quot;bubble primary &quot;&gt;Whos down for a pregame&lt;/div&gt;
  &lt;div class=&quot;bubble&quot;&gt;YES! I got the day off! Say when and where?&lt;/div&gt;
  &lt;div class=&quot;bubble primary&quot;&gt;Hows about Old Town at 4? we can get some grub and then head over to the venue&lt;/div&gt;
  &lt;div class=&quot;bubble&quot;&gt;Yeah getting the band back together&lt;/div&gt;
  &lt;div class=&quot;bubble&quot;&gt;show weekend?&lt;/div&gt;
  &lt;div class=&quot;bubble primary&quot;&gt;I&#39;m down!&lt;/div&gt;
  &lt;div class=&quot;bubble&quot;&gt;lets do this its been way to long since we were all together!&lt;/div&gt;
  &lt;div class=&quot;bubble primary &quot;&gt;Whos down for a pregame&lt;/div&gt;
  &lt;div class=&quot;bubble&quot;&gt;YES! I got the day off! Say when and where?&lt;/div&gt;
  &lt;div class=&quot;bubble primary&quot;&gt;Hows about Old Town at 4? we can get some grub and then head over to the venue&lt;/div&gt;
  &lt;div class=&quot;bubble&quot;&gt;Yeah getting the band back together&lt;/div&gt;
  &lt;div class=&quot;bubble&quot;&gt;show weekend?&lt;/div&gt;
  &lt;div class=&quot;bubble primary&quot;&gt;I&#39;m down!&lt;/div&gt;
  &lt;div class=&quot;bubble&quot;&gt;lets do this its been way to long since we were all together!&lt;/div&gt;
  &lt;div class=&quot;bubble primary &quot;&gt;Whos down for a pregame&lt;/div&gt;
  &lt;div class=&quot;bubble&quot;&gt;YES! I got the day off! Say when and where?&lt;/div&gt;
  &lt;div class=&quot;bubble primary&quot;&gt;Hows about Old Town at 4? we can get some grub and then head over to the venue&lt;/div&gt;
  &lt;div class=&quot;bubble&quot;&gt;Yeah getting the band back together&lt;/div&gt;
&lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年5月25日 06:46:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/76327853.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定