Home  >  Article  >  Web Front-end  >  CSS3绘制三角形实例介绍

CSS3绘制三角形实例介绍

WBOY
WBOYOriginal
2016-06-01 09:53:111180browse

利用CSS的border以及它的属性值transparent来实现三角形,其中最主要的是要明白由于div的高度跟宽度都为0,margin,padding也为0,所以元素框的大小就是他的border的叠加,由于相邻boder会重叠,故存在内容宽高时其实任意一边存在的border都是梯形的,当div内容宽高为0时,border就表现为三角形,将四个border的颜色设置为transparent表示边框透明,而将右边框颜色再设置为红色就发现三角形出现了,其实这个三角形是右边框。

<code class="language-html">   
   
   
    <style>    
        #triangle-up {    
            width: 0px;    
            height: 0px;   
            border: 100px solid transparent;   
            border-right:  100px solid red;   
         }   
    </style>   
    <div id="triangle-up"></div>   
   
  </code>

正常的框模型,div的内容width以及height均为50px.黑线划出来的区域就是它的右边框,呈现为一个梯形

<code class="language-html">   
   
   
    <style>    
        #triangle-up {    
            width: 50px;    
            height: 50px;   
            border: 100px solid red;    
            border-bottom: 100px solid red;   
         }   
    </style>   
    <div id="triangle-up"></div>   
   
  </code>

CSS3绘制三角形实例介绍

当div的内容width以及height均为0.黑线划出来的区域就是它的右边框,呈现为一个三角形

CSS3绘制三角形实例介绍

当div的内容width以及height均为0.上下左边框都为透明的时候,只有右边框显示为红色,三角形就看到了

CSS3绘制三角形实例介绍

结合css其他特性定能做出更有趣的一些效果!

更多文章:

纯css代码如何制作透明三角形

CSS 使用border来创建三角形的基本思路和实例

css border实现的三角形图案

css 巧用border属性制作各种图形(矩形,梯形,三角形)

css制作的圆,三角形,椭圆,箭头图标

CSS border

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