html - 自定义 CSS 聊天气泡

标签 html css chat msgbox

我使用 CSS 创建了一个聊天气泡。但我没有得到我想要的输出。这是我的代码,

body{
  background-color: lightgreen;
}

.bubble {
  margin: 100px;
  display: inline-block;
  position: relative;
  width: 300px;
  height: auto;
  background-color: white;
}
.border{
  border: 2px solid red;
}
.border-radius{
  border-radius: 10px;
  -webkit-border-radius: 10px;
  -moz-border-radius: 10px;

}
.triangle-right.border.right-top:before {
  content: ' ';
  position: absolute;
  width: 0;
  height: 0;
  left: auto;
  right: -26px;
  top: -2px;
  bottom: auto;
  border: 25px solid;
  border-color: red transparent transparent transparent;
}
.triangle-right.right-top:after{
  content: ' ';
  position: absolute;
  width: 0;
  height: 0;
  left: auto;
  right: -22px;
  top: -0.3px;
  bottom: auto;
  border: 25px solid;
  border-color: white transparent transparent transparent;
}
.chat{
  padding: 6px;
}
<div class="bubble triangle-right border-radius border right-top">
  <div class="chat">
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit,</p>
  </div>
</div>

我得到的输出:

enter image description here

我想要的输出: enter image description here

如何获得第二张图片中的输出。我想在右上角获得类似曲线的效果(就像第二张图片中一样)。谢谢。

最佳答案

您可以尝试radial-gradient()绘制曲线:

可能的例子

body{
  background-color: lightgreen;
}

.bubble {
  margin: 100px;
  display: inline-block;
  position: relative;
  width: 300px;
  height: auto;
  background-color: white;
}
.border{
  border: 2px solid red;
}
.border-radius{
  border-radius: 10px;
  -webkit-border-radius: 10px;
  -moz-border-radius: 10px;

}

.triangle-right.right-top:before{
  content: ' ';
  position: absolute;
  border-top:2px red solid;
  width:6px;
  top:-2px;
  right:0;
  height:10px;
  background:white;
}
.triangle-right.right-top:after{
  content: ' ';
  position: absolute;
  width: 30px;
  height: 40px;
  left: auto;
  right: -30px;
  top: -2px; 
  background:radial-gradient(ellipse at bottom right, transparent 28px, red 29px , red 30px , white 31px);
  border-top:solid red 2px; 
}
.chat{
  padding: 6px;
}
<div class="bubble triangle-right border-radius border right-top">
  <div class="chat">
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit,</p>
  </div>
</div>

根据您的需要调整周大小和位置。

关于html - 自定义 CSS 聊天气泡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66230600/

相关文章:

css - 如何使用其父容器制作 svg 比例尺?

javascript - 有没有办法一次性在所有页面中包含一个 &lt;script&gt; 或 <link> ?

html - 在html中嵌入文本文件

html - 背景幻灯片放映 Safari

JavaScript-如何在 div 中打印 p 元素

ios - UItableview 行与文本字段重叠

jquery - Prettyphoto 在页面开始水平 1page 网站上加载

css - 为动画和其他属性使用双供应商前缀

php - 使用 PHP 和 jQuery 进行实时聊天。在哪里存储信息? mysql还是文件?

facebook - Facebook Chat 如何跨窗口/标签同步对话