原码笔记

原码笔记

详解CSS3 用border写 空心三角箭头 (两种写法)

小诸哥 0

之前一直在寻找这种空心三角箭头, 终于知道了原理! 自己记录一下,顺便分享给之前跟我一样想要的撸友们~

第一种写法 利用常见的 after伪元素

  1. <!DOCTYPE html>
  2. <html>
  3.      <head>
  4.          <meta charset="UTF-8">
  5.          <title></title>
  6.          <style type="text/CSS">
  7.              .arrow {
  8.                  width: 20px;
  9.                  height: 4px;
  10.                  margin: 0 auto 7px;
  11.                  border-left: 4px solid transparent;
  12.                  border-right: 4px solid transparent;
  13.                  border-bottom: 4px solid #343c99;
  14.                  transform: rotate(45deg);
  15.                  transform-origin: left;
  16.              }
  17.             
  18.              .arrow:after {
  19.                  content: '';
  20.                  display: block;
  21.                  width: 100%;
  22.                  height: 100%;
  23.                  border-left: 4px solid transparent;
  24.                  border-right: 4px solid transparent;
  25.                  border-top: 4px solid #343c99;
  26.                  position: absolute;
  27.                  right: -10px;
  28.                  top: -14px;
  29.                  transform: rotate(90deg);
  30.                  transform-origin: bottom;
  31.              }
  32.          </style>
  33.      </head>
  34.      <body>
  35.          <div class="arrow"></div>
  36.      </body>
  37. </html>

第二种写法相对于比较简单

  1. <!DOCTYPE html>
  2. <html>
  3.      <head>
  4.          <meta charset="UTF-8">
  5.          <title></title>
  6.          <style type="text/css">
  7.              /*简单*/
  8.              .wb_arrow{
  9.                  border-right: 2px solid #343c99;
  10.                  border-top: 2px solid #343c99;
  11.                  height: 10px;
  12.                  width: 10px;
  13.                  margin:50px auto 0;
  14.                  transform: rotate(deg);
  15.                  -webkit-transform: rotate(0deg);
  16.                  /*不加这两个属性三角会比上一个略丑, 大家可以试一下*/
  17.                  border-left: 2px solid transparent;
  18.                  border-bottom: 2px solid transparent;
  19.              }
  20.          </style>
  21.      </head>
  22.      <body>
  23.          <div class="wb_arrow"></div>
  24.      </body>
  25. </html>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

标签: 详解 CSS border 写法