登录  /  注册
css实现三角形及应用示例_html/css_WEB-ITnose
php中文网
发布: 2016-06-24 11:51:19
原创
849人浏览过

css实现三角形,网上讲了很多,但我发现一般都是三角向上或者向下的,向左向右这两方向似乎讲得很少,本人试了一下,发现原来在IE下很难搞~~(万恶的IE)...
css实现三角形的原理是:当元素的宽高为0,边框(border)不为0时,四个角边框交界重叠处分45度角平分。讲得很别扭~~~上个图吧:
.triangle {
border-color: red green blue pink;
border-style: solid;
border-width: 20px 20px 20px 20px;
width: 0;
height: 0;
}



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

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



怎样?出来了吧~~

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

向左: .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);
}


html+css:

Js代码

  1. css三角形
  • 知道有些同学要直接看效果的,哈哈:看

    下载

    三角形是出来了,那我们看一个应用的例子(结合了之前写的fadeIn,fadeOut):

    http://kingkit.com.cn/KUI/Tip.html

    完整打包

  • Triangle3.rar
  • 来源:php中文网
    本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
    热门推荐
    热门教程
    更多>
    最新下载
    更多>
    网站特效
    网站源码
    网站素材
    前端模板
    关于我们 免责申明 意见反馈 讲师合作 广告合作 技术文章
    php中文网:公益在线php培训,帮助PHP学习者快速成长!
    关注服务号 技术交流群
    PHP中文网订阅号
    每天精选资源文章推送
    PHP中文网APP
    随时随地碎片化学习
    PHP中文网抖音号
    发现有趣的

    Copyright 2014-2023 //m.sbmmt.com/ All Rights Reserved | 苏州跃动光标网络科技有限公司 | 苏ICP备2020058653号-1

     | 本站CDN由 数掘科技 提供

    登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学