css - How to bring the curved tail behind the img - Stack Overflow

admin2025-04-30  1

I am trying to get the curved tail to be behind the image, but cannot achieve this. I've tried the z-index and it doesn't work.

.bubble {
  position: relative;
  height: 150px;
  width: 255px;
  margin-right: 5px;
  border-radius: 25px 25px 0 25px;
  border: 2px solid #fff;
  background-image: url(.jpg);
  background-size: contain;
}

.bubble::after {
  content: "";
  position: absolute;
  right: 0;
  background-color: transparent;
  bottom: -50px;
  height: 50px;
  z-index: 0;
  width: 25px;
  border-top-right-radius: 25px;
  box-shadow: 0 -25px 0 0 #fff;
}
<div class="bubble"></div>

I am trying to get the curved tail to be behind the image, but cannot achieve this. I've tried the z-index and it doesn't work.

.bubble {
  position: relative;
  height: 150px;
  width: 255px;
  margin-right: 5px;
  border-radius: 25px 25px 0 25px;
  border: 2px solid #fff;
  background-image: url(https://ines-valdovinos.de/images/blog-bubble_teaser.jpg);
  background-size: contain;
}

.bubble::after {
  content: "";
  position: absolute;
  right: 0;
  background-color: transparent;
  bottom: -50px;
  height: 50px;
  z-index: 0;
  width: 25px;
  border-top-right-radius: 25px;
  box-shadow: 0 -25px 0 0 #fff;
}
<div class="bubble"></div>

I've tried z-index 0 and -1 and it does not work.

Share Improve this question edited Jan 4 at 21:30 Temani Afif 276k28 gold badges368 silver badges487 bronze badges asked Jan 4 at 21:23 enesseness 12 bronze badges 1
  • 1 z-index: -1 works fine in the given example – Temani Afif Commented Jan 4 at 21:31
Add a comment  | 

1 Answer 1

Reset to default 1

Here is the solution you need. Please apply this code and test it. Let me know if it doesn't work.

.bubble {
  position: relative;
  height: 150px;
  width: 255px;
  margin-right: 5px;
  border-radius: 25px 25px 0 25px;
  border: 2px solid #fff;
  background-image: url(https://ines-valdovinos.de/images/blog-bubble_teaser.jpg);
  background-size: cover;
  background-position: center;
  z-index: 1;
}

.bubble::after {
  content: "";
    position: absolute;
    z-index: -1;
    bottom: -14px;
    right: -39px;
    width: 29px;
    height: 19px;
    background: #fff;
    -webkit-border-bottom-right-radius: 40px 50px;
    -moz-border-radius-bottomright: 40px 50px;
    border-bottom-left-radius: 66px 50px;
    -webkit-transform: translate(-10px, -2px);
    -moz-transform: translate(-10px, -2px);
    -ms-transform: translate(-10px, -2px);
    -o-transform: translate(-10px, -2px);
    transform: translate(-10px, -2px);
}

.bubble::before {
    content: "";
    position: absolute;
    z-index: -1;
    bottom: -13px;
    right: -14px;
    height: 16px;
    border-right: 30px solid #970d87;
    background: #970d87;
    -webkit-border-bottom-right-radius: 24px 41px;
    -moz-border-radius-bottomright: 80px 50px;
    border-bottom-left-radius: 80px 50px;
    -webkit-transform: translate(0, -2px);
    -moz-transform: translate(0, -2px);
    -ms-transform: translate(0, -2px);
    -o-transform: translate(0, -2px);
    transform: translate(0, -2px);
}
    <div class="bubble"></div>

转载请注明原文地址:http://anycun.com/QandA/1746027061a91533.html