【问题标题】:How to place curved arrow on top of your speech bubble? [duplicate]如何将弯曲的箭头放在讲话泡泡的顶部? [复制]
【发布时间】:2021-01-15 22:50:06
【问题描述】:

我想使用 css. 创建一个类似于下图的对话气泡

我该怎么做呢?

【问题讨论】:

  • 从像素化来看,这可能只是一张图片。但是您可以使用border-radius 实现类似的效果。请尝试一下,如果遇到困难,请发布您的代码。

标签: html css css-shapes


【解决方案1】:

您可以使用带有透明圆圈的radial-gradient 来创建对话气泡的弯曲尖端。将其应用于气泡的 ::before 伪元素,使其放置在您的对话气泡 div 的顶部。

.bubble::before {
  content: '';
  height: 30px;
  width: 30px;
  background: radial-gradient(circle at 100% 0, transparent 30px, cornflowerblue 0);
  display: block;
  margin-left: 100px;
}

.message {
  padding: 10px 20px;
  width: 300px;
  background: cornflowerblue;
  display: block;
  font-family: sans-serif;
  color: floralwhite;
  font-size: 18px;
  border-radius: 0 0 10px 10px;
}
<div class="bubble">
  <div class="message">
     <p>"Tell me and I forget. Teach me and I remember. Involve me and I learn."<p>
     <small>Benjamin Franklin</small>
  </div>
</div>

在悬停时添加边框

您可以将::after 伪元素与z-index 结合使用,以在将鼠标悬停在对话气泡上时创建边框效果。

.bubble::before,
.bubble::after {
  content: '';
  display: block;
  position: absolute;
}

.bubble::before {
  background: radial-gradient(circle at 95% -2px, transparent 25px, cornflowerblue 0);
  left: 103px;
  top: 10px;
  z-index: 1;
  height: 25px;
  width: 25px;
}

.bubble::after {
  background: radial-gradient(circle at 100% 0, transparent 30px, coral 0);
  left: 100px;
  top: 0px;
  z-index: -1;
  height: 30px;
  width: 30px;
  display: none;
}

.message {
  padding: 10px 20px;
  width: 300px;
  background: cornflowerblue;
  display: block;
  font-family: sans-serif;
  color: floralwhite;
  font-size: 18px;
  border-radius: 0 0 10px 10px;
  border: 3px solid white;
  margin-top: 30px;
}

.bubble:hover > .message {
  border: 3px solid coral;
}

.bubble:hover::after {
  display: block;
}
<div class="bubble">
  <div class="message">
     <p>"Tell me and I forget. Teach me and I remember. Involve me and I learn."<p>
     <small>Benjamin Franklin</small>
  </div>
</div>

【讨论】:

  • 如果我需要在悬停时为其添加边框如何为它提供 css?
  • 查看更新的答案。
猜你喜欢
  • 2015-07-29
  • 1970-01-01
  • 2011-05-25
  • 2018-04-14
  • 2018-11-16
  • 1970-01-01
  • 2015-07-25
  • 1970-01-01
  • 2017-01-25
相关资源
最近更新 更多