CSS三角箭头应用实践
建站知识 2021-07-03 08:15www.168986.cn长沙网站建设
用CSS来制作无图片带箭头的DIV方框(此代码比较适合追求纯代码者)
这类效果也可以用图片背景来实现,代码会更简洁
CSS代码
CSS Code复制内容到剪贴板
- div.container{position:absolute;
- :30px;
- left:40px;
- font-size: 9pt;
- display:block;
- height:100px;
- width:200px;
- background-color:transparent;
- border:1px solid #666;
- }
- s{
- position:absolute;
- :-20px;
- :-22px;
- left:20px;
- display:block;
- height:0;
- width:0;
- font-size: 0;
- line-height: 0;
- border-color:transparent transparent #666 transparent;
- border-style:dashed dashed solid dashed;
- border-width:10px;
- }
- i{position:absolute;
- :-9px;
- :-9px;
- left:-10px;
- display:block;
- height:0;
- width:0;
- font-size: 0;
- line-height: 0;
- border-color:transparent transparent #fff transparent;
- border-style:dashed dashed solid dashed;
- border-width:10px;
- }
- .content{
- border:1px solid #666;
- -moz-border-radius:3px;
- -webkit-border-radius:3px;
- position:absolute;
- background-color:#fff;
- width:100%;
- height:100%;
- padding:5px;
- :-2px;
- border-:1px solid #666;
- border-:1px solid #666;
- border-left:none;
- border-right:none;
- height:102px;
- box-shadow: 3px 3px 4px #999;
- -moz-box-shadow: 3px 3px 4px #999;
- -webkit-box-shadow: 3px 3px 4px #999;
- / For IE 5.5 - 7 /
- filter: progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#999999');
- / For IE 8 /
- -ms-filter: "progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#999999')";
- }
HTML代码
XML/HTML Code复制内容到剪贴板
- <div class="container">
- <div class="content">
- <br>这是框中的文字,可动态显示。高度自动增加,应该不错吧^_^
- </div>
- <s>
- <i></i>
- </s>
- </div>
效果图
这次介绍下CSS制作三角箭头
通常,我们做上图那个三角形,一般都是做张图,而且需要两张,因为一般都是下拉菜单的效果,需要有个hover的样式,箭头是反的。那是不是有更好的办法呢,毕竟要用两张图片来解决这么一个小问题太浪费资源了,于是,狼蚁网站SEO优化我要用纯CSS的方法来解决这一问题,用到的只需css的一个属性,就是border-width
我们先来看个样式,如果设置元素边框,会怎么样
似乎看不出什么,让我给四个边框加上不同的颜色吧再看看吧
是不是发现了些什么?对,让我们把中间的文字去掉吧
这样,就出现4个三角形了,然后我们如果需要顶部那个三角形,只需要将border的left、right、bottom设置成背景色就行了
这样,我们需要的三角形就出现了,并且可以设置4个不同方向的了
样式代码很简单,就几句话
CSS Code复制内容到剪贴板
- float: left;
- border-style: solid; border-width: 10px;
- border-color: #000 #c #c #c;
- height: 0;
- width: 0;
- font-size: 0;
实际应用
比如我们要使用向下的箭头(兼容IE6写法)
HTML代码
XML/HTML Code复制内容到剪贴板
- <div class="demo"><span class="bottom-arrow"></span></div>
CSS代码
CSS Code复制内容到剪贴板
- .demo{position:relative}
- .bottombottom-arrow{
- position:absolute;
- :10px;
- left:0px;
- border-style:solid;
- border-width:100px;
- border-color:#000000 transparent transparent transparent;/上边框设置想要的颜色/
- height:0;
- width:0;
- font-size:0;
- _border-color:#000000 tomato tomato tomato ; /边框透明色 For IE6-/
- _filter:chroma(color=tomato);/边框透明色 For IE6-/
- }
说明
这里的演示是用了边框透明色,如果你用不到透明的话,直接设置border-color为你需要的颜色就可以了,免去为了兼容IE6的透明边框滤镜写法
Chroma属性可以设置一个对象中指定的颜色为透明色,它的表达式如下
CSS Code复制内容到剪贴板
- FilterChroma(color=color)
这个属性的表达式是不是很简单,它只有一个参数。只需把您想要指定透明的颜色用Color参数设置出来就可以了。
上一篇:CSS选择器学习攻略
下一篇:利用CSS3的transition属性实现滑动效果
长沙网站设计
- 如何自己建一个网站 自己想建个网站,怎么建
- 如何制作网站免费建站 创建网站免费注册
- html简单网页代码 html简单网页代码超链接
- dreamweaver网页制作 dreamweaver网页制作模板
- 上海网站建设 上海网站建设制作微信
- 如何制作网站和网页 如何制作一个网页
- html网页制作代码大全 端午节html网页制作代码大
- app开发公司 app开发公司前十名
- html网页制作 html网页制作文字居中
- app制作一个需要多少钱 请人制作一个app多少钱
- 成都网站制作 成都网站制作维护
- 百度建一个网站多少钱 百度做个公司网站要多少
- html+css网页制作成品 web网页制作成品css+javascrip
- html网页制作案例 html网页设计案例
- html+css网页制作成品 web网页制作成品css+javascrip
- 个人网站模板 个人网站模板HTML