hgq's docs
主页
ES6-阮一峰 (opens new window)
Vue文档 (opens new window)
Axios文档 (opens new window)
Vue Router (opens new window)
Vuex文档 (opens new window)
面试题-Vue (opens new window)
面试题-JS (opens new window)

guoguoqiqi

漫不经心的向往
主页
ES6-阮一峰 (opens new window)
Vue文档 (opens new window)
Axios文档 (opens new window)
Vue Router (opens new window)
Vuex文档 (opens new window)
面试题-Vue (opens new window)
面试题-JS (opens new window)
  • 怎么解决移动端1px问题
  • 说一说对BFC的理解
  • CSS的盒子模型
  • 说一说对flex布局的认识
  • 网格布局
  • 伪类选择器和伪元素
  • 怎么实现响应式布局
  • css中的选择器有哪些、哪些可以继承
  • 如何做移动端适配
  • 如何清除浮动
  • em、rem区别
  • display none与visibility hidden的区别
  • z-index失效的场景
  • 在页面上隐藏元素的方法有哪些
  • css选择器中first-child与first-of-type的区别
  • 用css绘制三角形及其原理
    • 说一说box-sizing属性
    • 说一说水平垂直居中的布局方法
    • CSS 常见布局方式
    • CSS3的新特性有哪些
    • 圣杯布局和双飞翼布局
    • inline、block、inline-block这三个属性值有什么区别
    • 说一说css的预处理器
    • 如果要做优化,CSS提高性能的方法有哪些
    • CSS3常见动画有哪些
    • 怎样画一条0点5px的线
    • CSS
    guoguoqiqi
    2022-02-27

    用css绘制三角形及其原理

    # 原理

    首先创建一个宽高为0,但是有边框的四边形。

    <div class='rect'></div>
    <style>
        .rect {
          width: 0;
          height: 0;
          background-color: #fff;
          border-right: 100px solid rgb(34, 230, 220);
          border-left: 100px solid rgb(202, 146, 25);
          border-top: 100px solid rgb(29, 156, 194);
          border-bottom: 100px solid rgb(16, 204, 101);
        }
      </style>
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12

    效果:

    image

    可以看出其实四个边框就是四个三角形,如果只要得到一个三角形,只需要将另外三个设置为透明即可。(background设置为transparent)

    <style>
      .rect {
        width: 0;
        height: 0;
        background-color: #fff;
        border-right: 100px solid transparent;
        border-left: 100px solid transparent;
        border-top: 100px solid rgb(29, 156, 194);
        border-bottom: 100px solid transparent;
      }
    </style>
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11

    image

    # 参考文章链接

    CSS三角形的实现原理及运用 (opens new window)

    ← css选择器中first-child与first-of-type的区别 说一说box-sizing属性→

    最近更新
    01
    vuex数据持久化怎么做
    05-22
    02
    vue的动态路由怎么配置使用
    05-22
    03
    vue权限控制一般怎么做
    05-22
    更多文章>
    Theme by Vdoing | Copyright © 2022-2022 Guoquoqiqi | MIT License
    • 跟随系统
    • 浅色模式
    • 深色模式
    • 阅读模式