如何翻转CSS气泡三角形位置?

4

Fiddle

HTML:

<blockquote class="rectangle-speech-border">
    <p>This is a blockquote that is styled to look like a speech bubble</p>
</blockquote>

CSS:

.rectangle-speech-border {
  position:relative;
  padding:50px 15px;
  margin:1em 0 3em;
  border:10px solid #5a8f00;
  text-align:center;
  color:#333;
  background:#fff;
  /* css3 */
  -webkit-border-radius:20px;
  -moz-border-radius:20px;
  border-radius:20px;
}

/* creates larger curve */
.rectangle-speech-border:before {
  content:"";
  position:absolute;
  z-index:10;
  bottom:-40px;
  left:50px;
  width:50px;
  height:30px;
  border-style:solid;
  border-width:0 10px 10px 0;
  border-color:#5a8f00;
  background:transparent;
  /* css3 */
  -webkit-border-bottom-right-radius:80px 50px;
  -moz-border-radius-bottomright:80px 50px;
  border-bottom-right-radius:80px 50px;
  /* reduce the damage in FF3.0 */
  display:block;
}

/* creates smaller curve */
.rectangle-speech-border:after {
  content:"";
  position:absolute;
  z-index:10;
  bottom:-40px;
  left:50px;
  width:20px;
  height:30px;
  border-style:solid;
  border-width:0 10px 10px 0;
  border-color:#5a8f00;
  background:transparent;
  /* css3 */
  -webkit-border-bottom-right-radius:40px 50px;
  -moz-border-radius-bottomright:40px 50px;
  border-bottom-right-radius:40px 50px;
  /* reduce the damage in FF3.0 */
  display:block;
}

/* creates a small circle to produce a rounded point where the two curves meet */
.rectangle-speech-border > :first-child:before {
  content:"";
  position:absolute;
  bottom:-40px;
  left:45px;
  width:10px;
  height:10px;
  background:#5a8f00;
  /* css3 */
  -webkit-border-radius:10px;
  -moz-border-radius:10px;
  border-radius:10px;
}

/* creates a white rectangle to cover part of the oval border*/
.rectangle-speech-border > :first-child:after {
  content:"";
  position:absolute;
  bottom:-10px;
  left:76px;
  width:24px;
  height:15px;
  background:#fff;
}

示例取自:Nicolas Gallagher

这个文本气泡基本上向左和底部左侧弯曲。我想完全复制它,只是把它放在右下方并向右弯曲。只需翻转即可。

我尝试将权利改成左侧,但没有发生任何事情。有人可以告诉我需要更改什么来翻转这个气泡吗?

1个回答

2

您的意思是这个吗?

如果您想改变几何形状,您需要调整边框宽度和边框半径。此外,我将伪类从:after更改为:before,并在元素中反之亦然,并将边框半径从右到左进行了更改。

.rectangle-speech-border {
  position:relative;
  padding:50px 15px;
  margin:1em 0 3em;
  border:10px solid #5a8f00;
  text-align:center;
  color:#333;
  background:#fff;
  /* css3 */
  -webkit-border-radius:20px;
  -moz-border-radius:20px;
  border-radius:20px;
}

/* creates larger curve */
.rectangle-speech-border:after {
  content:"";
  position:absolute;
  z-index:10;
  bottom:-40px;
  left:400px;
  width:20px;
  height:30px;
  border-style:solid;
  border-width:0 0 10px 10px;
  border-color:#5a8f00;
  background:transparent;
  /* css3 */
  -webkit-border-bottom-left-radius:40px 50px;
  -moz-border-bottom-left-radius:40px 50px;
  border-bottom-left-radius:40px 50px;
  /* reduce the damage in FF3.0 */
  display:block;
}

/* creates smaller curve */
.rectangle-speech-border:before {
  content:"";
  position:absolute;
  z-index:10;
  left:370px;
  width:50px;
  height:30px;
  bottom: -40px;
  border-style:solid;
  border-width:0 0 10px 10px;
  border-color:#5a8f00;
  background:transparent;
  /* css3 */
  -webkit-border-bottom-left-radius:40px 50px;
  -moz-border-bottom-left-radius:40px 50px;
  border-bottom-left-radius:40px 50px;
  /* reduce the damage in FF3.0 */
  display:block;
}

/* creates a small circle to produce a rounded point where the two curves meet */
.rectangle-speech-border > :first-child:before {
  content:"";
  position:absolute;
  bottom:-40px;
  left:425px;
  width:10px;
  height:10px;
  background:#5a8f00;
  /* css3 */
  -webkit-border-radius:10px;
  -moz-border-radius:10px;
  border-radius:10px;
}

/* creates a white rectangle to cover part of the oval border*/
.rectangle-speech-border > :first-child:after {
  content:"";
  position:absolute;
  bottom:-10px;
  left:376px;
  width:24px;
  height:15px;
  background:#fff;
}
<blockquote class="rectangle-speech-border">
    <p>This is a blockquote that is styled to look like a speech bubble</p>
</blockquote>


OP指定尾部应向右弯曲,所以接近但不完全。 - Maximillian Laumeister
@MaximillianLaumeister 稍等几分钟,正在处理中。 - AleshaOleg
嗯,真是个很好的问题! - AleshaOleg
是的,Max 是正确的。我希望它向右弯曲。 - o_O
是的,这正是我想要的。让我检查一下你的代码,这样我就可以学习如何在将来做到这一点。非常感谢。 - o_O

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