david2tdw / blog

学习记录
1 stars 1 forks source link

[CSS] tips带有描边的小箭头 #111

Open david2tdw opened 4 years ago

david2tdw commented 4 years ago

css多种方法实现一个tips带有描边的小箭头

david2tdw commented 4 years ago

background和border背景描边旋转:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>tips: background和border背景描边旋转</title>
    <style>
      .box {
        position: relative;
        padding: 10px;
        text-align: center;
        border: 1px solid #f60;
        border-radius: 5px;
      }
      .box::after {
        content: '';
        position: absolute;
        left: 50%;
        display: table;
        width: 10px;
        height: 10px;
        margin-left: -5px;
        transform: rotate(-45deg); /* 旋转矩形*/
        z-index: 1; /* 覆盖在文字框上面*/
        bottom: -6px; /* 箭头定位 */
        border-bottom: 1px solid #f60; /* 显示下边框 */
        border-left: 1px solid #f60; /* 显示右边框 */
        background-color: #fff; /* 覆盖上面的边线 */
      }
    </style>
  </head>
  <body>
    <div class="box">
      <div>this is content.</div>
    </div>
  </body>
</html>
david2tdw commented 4 years ago

linear-gradient和border:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .box {
        position: relative;
        padding: 10px; /* 重要 防止内容被覆盖 */
        text-align: center;
        border: 1px solid #f60;
        border-radius: 5px;
      }
      .box::after {
        content: '';
        position: absolute;
        left: 50%;
        display: table;
        width: 10px;
        height: 10px;
        margin-left: -5px;
        transform: rotate(-135deg); /* 旋转矩形*/
        z-index: 1; /* 覆盖在上面 */
        bottom: -6px;
        border-top: 1px solid #f60;
        border-left: 1px solid #f60;
        /* 角度:从右下角开始。 起始透明,渐变终点7px,结束颜色白色,结束终点0 */
        background: linear-gradient(-45deg, transparent 7px, #fff 0);
        /* background: linear-gradient(-45deg, red 7px, #fff 0); */
      }
    </style>
  </head>
  <body>
    <div class="box">
      <div>this is content.
        background-image: linear-gradient(direction, color-stop1, color-stop2, ...);
      </div>
    </div>
  </body>
</html>

linear-gradient