css中的:before与:after的简单使用
直接上代码,不多说了!
画三角形
1)、
<style type="text/css">
.triangle{
width: 0;
height: 0;
/*border: 50px transparent solid;*//*当没有这句时,至少有2个方向的边框才能成形,比如下面的一组*/ border-top: 50px solid black;
border-right: 50px solid purple;
/*border-bottom: 50px solid blue;
border-left: 50px solid red;*/
}
</style>
<div class="triangle"></div>

2)、
<style type="text/css">
.triangle1{
width: 0;
height: 0;
border: 50px transparent solid;/*transparent表示边框颜色是透明的,solid表示边框是实线的*/
border-top-color: black;
border-bottom-color: black;
}
</style>
<div class="triangle1"></div>

3)、类似QQ或微信中的提示框,带有三角形的框

<style type="text/css">
.wechat-triangle{
position: relative;
width: 150px;
height: 36px;
border: 1px solid black;
border-radius: 5px;
background: rgba(245, 245, 245, 1);
} /*.wechat-triangle:before{
content: "";
display: block;
position: absolute;
top: 8px;
width: 0;
height: 0;
border: 6px transparent solid;
left: -12px;
border-right-color: rgba(245,245,245,1);
}*/ .wechat-triangle:before, .wechat-triangle:after{
content: "";
display: block;
position: absolute;
top: 8px;
width: 0;
height: 0;
border: 6px transparent solid;
} .wechat-triangle:before{
left: -11px;
border-right-color: rgba(245,245,245,1);
z-index: 1;
} .wechat-triangle:after{
left: -12px;
border-right-color: rgba(0,0,0,1);
z-index: 0;
} .wechat-triangle1{
width: 120px;
height: 30px;
position: relative;
border: 1px solid black;
border-radius: 5px;
background: rgba(245,245,245,1);
} .wechat-triangle1:before, .wechat-triangle1:after{
content: "";
width: 0;
height: 0;
display: block;
position: absolute;
top: 5px;
border: 4px transparent solid;
} .wechat-triangle1:before{
left: -8px;
border-right-color: rgba(245,245,245,1);
z-index: 1;
} .wechat-triangle1:after{
left: -9px;
border-right-color: rgba(0,0,0,1);
z-index: 0;
}
</style> <div class="wechat-triangle"></div>
<div class="wechat-triangle1"></div>
其中rgba是由颜色与透明度组成,透明度是[0,1]。
4)、提示框,当鼠标放到上面时,就会有提示信息

<style>
.tip{
display: inline-block;
width: 100px;
height: 30px;
line-height: 30px;
text-align: center;
position: relative;
border: 1px solid #ccc;
cursor: pointer;
} .tip:before, .tip:after{
position: absolute;
opacity: 0;
} .tip:before{
content: '';
width: 0;
height: 0;
border-width: 6px;
border-style: solid;
border-color: #222 transparent transparent transparent;
top: -6px;
} .tip:after{
content: attr(data-tips);
white-space: nowrap;
font-size: 14px;
color: #fff;
background-color: #222;
top: -36px;
left: 5px;
border-radius: 6px;
padding: 0 10px;
text-shadow: 0 0 5px #000;
-moz-box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
-webkit-box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
-moz-box-sizing: boder-box;
-webkit-box-sizing: boder-box;
box-sizing: boder-box;
} .tip:hover:before, .tip:hover:after{
opacity: 1;
}
</style>
<div class="tip" data-tips="沉冤得雪魂归战场">琅琊榜</div>
css中的:before与:after的简单使用的更多相关文章
- css中的em 简单教程 -- 转
先附上原作的地址: https://www.w3cplus.com/css/px-to-em 习惯性的复制一遍~~~~ -------------------------------我是分界线---- ...
- css中box-sizing简单说明(标准盒式模型和怪异盒式模型)
今天写程序做布局的时候,遇到关于css中盒式模型的问题,百度了下这属性的解释,脑大啊,文字太绕看不懂.怎么办,于是自己动动手写了段程序测试,嗯,不错,一看效果就恍然大明白了.这里简单说明下,也可能说得 ...
- 简单聊聊CSS中的3D技术之“立方体”
简单聊聊CSS中的3D技术之“立方体” 大家好,我是今天的男一号,我叫小博主. 今天来聊一下我在前端“逆战班”学习中遇到的颇为有趣的3D知识.前端学习3周,见识稀疏,在下面的分享中如有不对的地方请大家 ...
- css中的毛玻璃(不是透明度) 简单文档
其实毛玻璃很简单 只需要在css中加入 backdrop-filter:blur(8px); 8px是模糊力度 注意:使用该方法前需要设置背景不能是透明(如果是显示这个元素下面的图像记得半透明,例子就 ...
- HTML和CSS设置动态导航以及CSS中伪元素的简单说明
HTML页面代码: <!DOCTYPE html> <html> <head> <title>Test</title> <meta c ...
- 总结一下CSS中的定位 Position 属性
在CSS中,Position 属性经常会用到,主要是绝对定位和相对定位,简单的使用都没有问题,尤其嵌套起来,就会有些混乱,今记录总结一下,防止久而忘之. CSS position 属性值: absol ...
- CSS中一些常见的兼容性问题
CSS中一些兼容性问题就是浏览器兼容,而这些浏览器兼容问题主要是Ie和FF之间的争斗. CSS hack中的一些事: 我们为了让页面形成统一的效果,要针对不同的浏览器或不同版本写出对应可解析的CSS样 ...
- css中的负边距
css中的负边距(negative margin)是布局中的一个常用技巧,只要运用得合理常常会有意想不到的效果.很多特殊的css布局方法都依赖于负边距,所以掌握它的用法对于前端的同学来说,那是必须的. ...
- css中单位px、pt、em和rem的区别
国内的设计师大都喜欢用px,而国外的网站大都喜欢用em和rem,那么三者有什么区别,又各自有什么优劣呢? px :像素(Pixel).相对长度单位.像素px是相对于显示器屏幕分辨率而言的.(引自CSS ...
随机推荐
- centos 普通用户添加sudo权限
本文介绍下,在centos中为普通用户添加sudo权限的方法,供大家学习参考. 在centos中为普通用户增加sudo权限的简单方法,大家参考下. 1,修改/etc/sudoers文件,必须为visu ...
- 关于C与C++的struct,union,enum用法差异
对着代码说话: #include <stdio.h> #include <stdlib.h> struct test { int abc; }; enum _enum {A,B ...
- andriod Kernel configuration is invalid
error: ERROR: Kernel configuration is invalid. include/generated/autoconf.h or include/conf ...
- 【nodejs】关于 alert 和 document
Microsoft Windows [版本 6.1.7601] 版权所有 (c) 2009 Microsoft Corporation.保留所有权利. C:\Windows\system32>n ...
- 点击图标 标记为星标记事mac中修改默认的apache网站根目录位置
在Mac OS X中可以很方便的通过开启“Web共享”启用Apache服务:设置方法如下: 打开“系统设置偏好(System Preferences)” -> “共享(Sharing)” -&g ...
- 多态&&父类调用子类特有的方法
/* 多态 1.没有继承就没有多态 2.代码的体现:父类类型的指针指向子类对象 3.好处:如果函数\方法参数使用的是父类对象,可以传入父类.子类对象 4.局限性: 1>父类类型的变量,不能直接调 ...
- kali linux安装vm
https://download3.vmware.com/software/wkst/file/VMware-Workstation-Full-10.0.2-1744117.i386.bundle v ...
- CentOS 大量的TIME_WAIT解决方法
CentOS 大量的TIME_WAIT解决方法 最近个人博客总是出现无法打开的现象,具体表现为,打开页面需要等待n长时间,登陆系统后发现系统存在大量TIME_WAIT状态的连接,google了一下解决 ...
- ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
引子: 本项目在老电脑上用的是oracle10g,换新电脑装的是oracle11g,但运行项目本没有什么关系,本来说创建个用户,用PLSQL手工导入数据,再改几下配置文件即可跑起来--但实际启动中遇到 ...
- [BC]BestCoder Round#86小结
1001 [题意] 给定一个长度为n(n<=100000)的正整数序列,给出m(m<=100000)个子集合和的记录,问哪些一定比正确的记录多了 [题解] 对正整数序列求和,记录比和大的一 ...