页面中产生小三角块的样式
2017-07-23 20:30
134 查看
直接上图说明问题
问题说明
一般网站页面都会有三角方块,或者他们组合的图形。有人说可以直接叫美工切个图,不就完事了吗。当然这是可以的,也是重要方法之一,但是知识会固定死,遇到极端苛刻的场景需求,估计GG了。当然这是自己说给自己听的,与大神无关。大神越过知识点梳理
1.如何产生小方块:
使用块级元素或者行内块元素进行设置(强制转换元素类型当然也是可以的)代码如下:
{ width:0; height:0; border:100px solid transparent; border-left-top:red; }
2.产生小方块的方式
1).使用空的块级标签或行内块标签来设置,然后在定位到需要的位置。2). 使用伪元素来创建一个空标签,然后在定位到需要的位置。
开始效果的代码展示
<!DOCTYPE html> <html> <head> <title></title> <meta charset="utf-8"/> <style type="text/css"> *{ margin:0; padding: 0; } span{ display: block; /*注意行内元素没有效果,要转为块级元素或者行内块元素*/ width:0; height: 0; border-top:100px solid #abc; border-right: 100px solid #acb; border-bottom:100px solid #aaa; border-left: 100px solid #ff0; } p{ width:0; height: 0; border:100px solid transparent; /*transparent为透明色*/ border-top-color:red; /*想要顶部的三角形*/ margin-top:20px; /*设置两个距离*/ } h3{ width:0; height: 0; border:100px solid transparent; border-right-color:#f0f; border-bottom-color:#ff0; } a{ display: inline-block; width:120px; height: 50px; line-height: 50px; background-color: #FFA500; text-align: center; position: relative; margin:100px; /*设置与上边的距离*/ } /*a b{ position: absolute; top:0; left: 0; display: block; width: 0; height: 0; border:10px solid #fff; border-right-color: green; border-bottom-color:green; } a:hover{ background-color: pink; color:#fff; } a:hover b{ border-right-color: blue; border-bottom-color:blue; }*/ /*第二种方法实现折叠效果,使用伪元素来实现*/ a:before{ content: ""; display: block; position: absolute; left: 0; top:0; width: 0; height: 0; border:10px solid #fff; border-right-color: green; border-bottom-color:green; } a:hover{ background-color: pink; } </style> </head> <body> <span></span> <p></p> <h3></h3> <a href="#"> <b></b> 网站导航 </a> </body> </html>
使用三角块来实现面包屑导航
效果图如下:代码如下,实现原理(三角块加定位及伪元素)
<!DOCTYPE html> <html> <head> <title>test 面包导航效果</title> <meta charset="utf-8"/> <style type="text/css"> *{ margin:0; padding:0; } .nav{ display: inline-block; height: 80px; margin:20px auto; font-size:0; /*处理行内块默认的边距,或者使用float来设置*/ } .nav a{ display: inline-block; color:#fff; text-decoration: none; font:bold 18px/80px "微软雅黑"; height: 80px; background-color: #3498DB; padding:0px 40px 0px 80px; margin-right:10px; position: relative; } .nav a:after{ content: ''; width:0; height: 0; border:40px solid transparent; border-left-color:#3498DB; position: absolute; right:-80px; top:0; z-index: 10; } .nav a:before{ content: ''; width: 0; height: 0; border:40px solid transparent; border-left-color:#fff; position: absolute; left: 0; top:0; z-index: 1; } /*设置去掉第一个a标签的左边的*/ .nav a:nth-child(1):before{ display: none; } .nav a:nth-last-child(1):after{ display: none; } /*设置第一个,最后一个a标签的圆角*/ .nav a:first-child{ border-radius:5px; } .nav a:last-child{ border-radius:5px; } </style> </head> <body> <div class="nav"> <a href="#">Browse</a> <a href="#">Compare</a> <a href="#">order Confirmation</a> <a href="#">Checkout</a> </div> </body> </html>
送给一些努力奔跑的人
不多bb,做好自己,加油干!相关文章推荐
- jquery关于页面焦点的定位(文本框获取焦点时改变样式 )
- H5页面中删除iPhone自带样式
- s:actionmessage页面样式失效
- DHTML技术演示---动态设置页面文字样式
- 进入页面给HTML标签添加、移除样式
- 如何修改My97Date日期插件在本页面的样式;
- 六-1 检查和编辑页面和样式 概述
- request派发后的页面样式失效问题:绝对路径和相对路径
- jQuery给跳转后页面的导航栏添加选中后样式
- Vue2.0 给Tab标签页和页面切换过渡添加样式
- 页面背景 跟ps软件png图片背景的样式css
- CSS设置页面滚动条的样式
- 这两天使用jquery-mobile写手机页面遇到的append样式不生效,以及listview内容显示不完解决方法
- 折腾了一天的页面样式,从旧样式换为新样式,很坑跌
- aspx 页面提交造成页面样式混乱
- 登录页面重定向后页面样式丢失
- 单页面右侧导航样式
- 页面导入样式时,使用link和@import有什么区别?
- Form认证导致登陆页面的样式无效和图片不能显示的原因
- java后台与页面进行数据交互时产生乱码