html - css气泡,实现“倒三角(不知道算不算三角了)”可透明的。
巴扎黑
巴扎黑 2017-04-17 11:49:26
0
3
637

如图显示,右边那个三角要如何实现?

巴扎黑
巴扎黑

reply all(3)
Peter_Zhu

Haha, I looked at it and found it very interesting. I roughly understand what the original poster meant, that is, the line should be inward rather than outward.

First of all, I thought the border-radius property could be implemented, why do I think so? Because I think border-radius should be able to have negative values. A positive value means drawing a circle outward, and a negative value means drawing a circle inward.

I am still too naive, border-radius does not support negative values.

After the idea failed, another idea came to my mind, which is to implement it through covering. I just tried it and it seems feasible. Here is the code:

<span class="test"></span>
<style type="text/css">
  .test{
    display:inline-block;
    border-width:15px 0 15px 30px;
    border-color:transparent red;
    border-style:solid;
    position: relative;
  }
  .test::after{
    content:'';
    border: 30px solid white;
    border-radius: 50%;
    position: absolute;
    left: -32px;
  }
</style>

To briefly explain the idea, first construct a right-facing triangle. Students who don’t know how to construct can refer to this article about borders in CSS. Then draw a pseudo-class after to implement a circle. The background color is the same as the background color. By setting the position to cover the lower edge of the triangle below, the final effect is achieved.

In order to be more intuitive, I changed the background color of after,

In fact, there are big disadvantages in doing this, such as the actual width of the element will become larger, etc.

But I think the original poster’s request has been fulfilled. OooO, although it is a bit different from the original poster’s style.

Peter_Zhu

Irregular bubble pictures generally do not need to be drawn with code. They are generally implemented with image masks, canvas or dom.
///////////////////////////////////
-webkit-mask-image can be easily implemented The effect you want

http://output.jsbin.com/jeruxul

阿神
<!DOCTYPE html>
<html>

    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <style type="text/css">
        p {
            width: 0px;
            height: 0px;
            border-top: 50px solid red;
            border-right: 50px solid blue;
            border-bottom: 50px solid yellow;
            border-left: 50px solid green;
        }
    </style>

    <body>

        <p>

        </p>
    </body>

</html>

The tip of the bubble is an independent p. Change the unnecessary border color to the background color, and then use positioning to move it to the desired place

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template