博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
css实现三角形及应用示例
阅读量:7221 次
发布时间:2019-06-29

本文共 1604 字,大约阅读时间需要 5 分钟。

  hot3.png

css实现三角形,网上讲了很多,但我发现一般都是三角向上或者向下的,向左向右这两方向似乎讲得很少,本人试了一下,发现原来在IE下很难搞~~(万恶的IE)...

css实现三角形的原理是:当元素的宽高为0,边框(border)不为0时,四个角边框交界重叠处分45度角平分。讲得很别扭~~~上个图吧:

Html:

Css:
.triangle {                      border-color: red green blue pink;       border-style: solid;       border-width: 20px 20px 20px 20px;       width: 0;       height: 0;}
06124058_VQGw.jpg

那么,我们只有留下一条边框的时候会发现什么?

.triangle {                     border-color: red transparent transparent transparent;       border-style: solid;       border-width: 20px 20px 0px 20px;       width: 0;       height: 0;}
06124058_UZWX.jpg

怎样?出来了吧~~

同样道理,我们改成为向左向右的

向左:

.triangle {                    border-color: transparent red transparent transparent;      border-style: solid;      border-width: 20px 20px 20px 0px;      width: 0;      height: 0;}
向右:
.triangle {                    border-color: transparent transparent transparent red;     border-style: solid;     border-width: 20px 0px 20px 20px;     width: 0;     height: 0;}
大功造成!? 慢,你用的是什么浏览器?如果用的是非IE6的话,恭喜你!下面我们用IE6(咬牙切齿ing...)

原来,IE6默认给了背景黑色~~

只有好用IE专有的东东了,解铃还需系铃人(~_~)
首先,css hack,用下划线"_"!

_border-top-color: white;_border-bottom-color: white;
然后用chroma filter :
_filter: chroma(color =white);     
其实就是把不要的边过滤掉!
还要加上
font-size: 0;  line-height: 0;            
这样就彻底的去掉了黑色背景:
.triangle {      border-color: transparent  transparent transparent red;      border-style: solid;      border-width: 20px 0px 20px 20px;      font-size: 0;      line-height: 0;          width: 0;      height: 0;      _border-top-color: white;      _border-bottom-color: white;      _filter: chroma( color =white);}

转载于:https://my.oschina.net/i33/blog/94237

你可能感兴趣的文章
通过Bottledwater同步PostgreSQL中的数据变化到Kafka消息队列
查看>>
洛谷P4112 最短不公共子串
查看>>
Every Tom,Dick and Harry. 不管张三李四。
查看>>
Ubuntu开机显示器报错
查看>>
怎样查w3wp.exe对应的IIS站点
查看>>
USACO 2.1
查看>>
Python--常用的内置函数
查看>>
RabbitMQ入门-消息订阅模式
查看>>
【ZJOI2016】线段树
查看>>
分子公司部署辅助域控步骤
查看>>
表现与数据分离(MV*)
查看>>
由理解Java访问权限而产生的感触
查看>>
loadrunner脚本中写入脚本输出log到外部文件,分析参数取值方式
查看>>
Android之SQLite数据存储
查看>>
阅读天龙八部的代码有感----两种逻辑处理模式的比较
查看>>
iOS开发的一些奇巧淫技3
查看>>
linux 命令大全
查看>>
网站登录时记住密码
查看>>
越南菜在北京——西贡在巴黎的滋味
查看>>
SQL Server数据库备份:通过Windows批处理命令执行
查看>>