Home  >  Article  >  Web Front-end  >  How to use css to draw triangles directly and in dialogue form (code attached)

How to use css to draw triangles directly and in dialogue form (code attached)

不言
不言Original
2018-08-21 10:09:212052browse

The content of this article is about how to use css to directly draw triangles and triangles in dialogue form (with code). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you. helped.

In product display, triangles often appear, such as the triangle label in the upper left corner, or the triangle in the form of a dialogue, with a shadow effect, etc. I will record it here

1 , add triangles directly

<div>
    <div>
        <div></div>
        <div>想你呦</div>
    </div>
</div>
<style>
    body {
        background: #e5e5e5;
    }
    .triangleContainer {
        margin: 50px auto;
        width: 500px;
        height: 400px;
        background: #fff;
    }
    .triangleContent {
        position: relative;
    }
    .triangle {
        position: absolute;
        right: -70px;
        top: -70px;
        transform: rotate(45deg);
        /* 比较长的写法 */
        /*border-top: 70px solid transparent;*/
        /*border-bottom: 70px solid red;*/
        /*border-left: 70px solid transparent;*/
        /*border-right: 70px solid transparent;*/
        /* 简单写法 */
        border: 70px solid transparent;
        border-bottom-color: red;
    }
    .title {
        position: absolute;
        right: 8px;
        top: 17px;
        transform: rotate(45deg);
        font-size: 19px;
        color: #fff;
    }
</style>

How to use css to draw triangles directly and in dialogue form (code attached)

2, use pseudo-class to add triangles (with shadow effect)

Add two pseudo-classes: one pseudo-class implements triangle, Another use of positioning to achieve shadow effects

<view>
  <text>邀请越多的好友,中奖几率越高哦!</text>
  <text>我知道了</text>
</view>
.promptInfo{
  position: absolute;
  left: 5%;
  top: -28rpx;
  margin: 0 auto;
  padding: 20rpx 0;
  box-sizing: border-box;
  width: 88%;
  border-radius: 10rpx;
  z-index: 999;
  background: #fff;
  box-shadow: 3rpx 3rpx 3rpx rgba(0,0,0,.2);
  border: 0;
  font-size: 30rpx;
}
/* 添加与阴影颜色相同来形成三角形的阴影效果 */
.promptInfo::before{
  position: absolute;
  bottom: -21rpx;
  right: 110rpx;
  z-index: 999;
  border-top: 20rpx solid rgba(0,0,0,.2);
  border-left: 20rpx solid transparent;
  border-right: 20rpx solid transparent;
  content: ""
}
.promptInfo::after{
  position: absolute;
  bottom: -17rpx;
  right: 110rpx;
  z-index: 999;
  border-top: 20rpx solid #fff;
  border-left: 20rpx solid transparent;
  border-right: 20rpx solid transparent;
  content: ""
}
.promptInfo .inviteMessage{
  padding-left: 30rpx; 
}
.promptInfo .clickMessage {
  display: inline-block;
  margin-left: 15rpx;
  padding: 10rpx 20rpx;
  color: #fff;
  background: red;
  border-radius: 30rpx;
}

How to use css to draw triangles directly and in dialogue form (code attached)

Related recommendations:

css to create triangles, drop-down box triangles_html/css_WEB-ITnose

Use div css to implement triangles, with words inside the triangle_html/css_WEB-ITnose

css to implement rounded triangles method

The above is the detailed content of How to use css to draw triangles directly and in dialogue form (code attached). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn