如何使用CSS创建一个曲形的尾巴对话框?

10

我正在使用CSS创建一个对话框,目前已经完成了这一部分。

.says{
  width: 200px;
  padding: 20px;
  margin-right: 20px;
  background: #BF7EF2;
  color: #fff;
  box-shadow: -3px 3px 5px #C1B9C8;
  position: relative;
  border-radius: 5px;
}

.says:before{
  content: "";
  position: absolute;
  z-index: -1;
  top: 14px;
  right: -18px;
  height: 20px;
  border-right: 20px solid #BF7EF2;
  border-bottom-right-radius: 25px 20px;
  transform: translate(0, -4px);
  box-shadow: -3px 3px 5px #C1B9C8;
}

.says:after{
  content: "";
  position: absolute;
  z-index: -1;
  top: 7px;
  right: -18px;
  width: 30px;
  height: 30px;
  background: #fff;
  border-bottom-left-radius: 40px 35px;
  transform: translate(0px, -20px);
}
<div class="says">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ratione aut facere cupiditate, sunt, nisi fugiat consectetur officiis veniam!</div>

基本上,我使用了:before:after伪类并应用了border-radius。然后重叠在一起以达到期望的效果。现在,正如您所看到的,我在:after上使用了background: #fff,因为当前父元素的背景是白色。这将覆盖我应用程序中许多具有不同背景颜色的div。这是我目前遇到的问题。

例如-
enter image description here

我能否在:after上不使用background属性来实现相同的“气泡尾巴”?
^此行解释了这并不是所链接问题的重复。

或者通过完全不同的方式?


@web-tiki 这个链接的问题已经有了答案,他也在:after上使用了background属性,但这里不是这种情况。我不想使用背景,正如我在问题末尾所述。这是一个不同的场景,我认为不是重复的。 - aniskhan001
我明白你的意思,被接受的答案在几种背景颜色下都不起作用,但valsTylerH提供的方法可以。 - web-tiki
@web-tiki,我已经实现了与vals相同的效果,但我使用的形状不同。尾巴的锐边在其另一侧的中间位置。而TylerH的形状不是弯曲的,而是一个直角三角形。 - aniskhan001
1个回答

13

正如Webtiki所说,你可以通过修改我的先前回答来获得此结果(即便可能有点困难)

.container {
  width:300px;
  margin:5px;
}
.test 
{
position: relative;
width: 300px;
height: 150px;
padding: 0px;
background: pink;
border-radius: 6px;
}

.test:after {
    content: '';
    top: 1px;
    right: -29px;
    position: absolute;
    border: 0px solid;
    display: block;
    width: 38px;
     height: 26px;
    background-color: transparent;
    border-bottom-left-radius: 50%;
    border-bottom-right-radius: 50%;
    box-shadow: -21px 9px 0px 8px pink;
}
<div class="container">
  <div class="test"></div>
</div>
<img src="http://i.stack.imgur.com/MYlKY.png" alt="enter image description here">


谢谢!我现在有了想法。只需要微调一些属性来符合我的期望。我会编辑答案以符合我的偏好风格。 - aniskhan001
这太棒了!! - Itay

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接