首页 > 开发 > CSS > 正文

纯CSS绘制三角形箭头图案技术解析

2024-07-11 08:32:45
字体:
来源:转载
供稿:网友

最近我想修改一下这个网站,我想在上面放置一个提示框。这是很容易,但我想让提示框上有一个三角形的箭头。可是,一想到这需要使用图片,并且各种颜色,各种方向的箭头要准备无数种,这几乎是一种灾难。幸运的是,MooTools的核心开发着Darren Waddell告诉了我一个非常棒的技术:用CSS绘制三角形箭头。使用纯CSS,你只需要很少的代码就可以创作出各种浏览器都兼容的三角形箭头!

CSS代码

CSS Code复制内容到剪贴板
  1. /* create an arrow that points up */   div.arrow-up {   
  2.  width: 0;      height: 0;    
  3.  border-left: 5px solid transparent;  /* left arrow slant */    border-right: 5px solid transparent; /* right arrow slant */  
  4.  border-bottom: 5px solid #2f2f2f; /* bottom, add background color here */    font-size: 0;   
  5.  line-height: 0;    }   
  6.    /* create an arrow that points down */  
  7. div.arrow-down {     width: 0;    
  8.  height: 0;      border-left: 5px solid transparent;   
  9.  border-right: 5px solid transparent;     border-top: 5px solid #2f2f2f;   
  10.  font-size: 0;     line-height: 0;   
  11. }      
  12. /* create an arrow that points left */   div.arrow-left {   
  13.  width: 0;      height: 0;    
  14.  border-bottom: 5px solid transparent;  /* left arrow slant */    border-top: 5px solid transparent; /* right arrow slant */  
  15.  border-right: 5px solid #2f2f2f; /* bottom, add background color here */    font-size: 0;   
  16.  line-height: 0;    }   
  17.    /* create an arrow that points right */  
  18. div.arrow-rightright {     width: 0;    
  19.  height: 0;      border-bottom: 5px solid transparent;  /* left arrow slant */  
  20.  border-top: 5px solid transparent; /* right arrow slant */    border-left: 5px solid #2f2f2f; /* bottom, add background color here */  
  21.  font-size: 0;     line-height: 0;   
  22. }   
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表