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 ...
随机推荐
- 解决Discuz“完善用户资料”任务不能完成的问题
最近用 Discuz X3.2 搭建了个论坛,在测试过程中发现"完善用户资料"这个官方自带的任务有个Bug,将所有的资料都填写完成后,任务仍然无法完成,而且没有明确提示有哪些项目没 ...
- CLR via C# I/O基元线程同步构造
1. 分为用户模式构造和内核模式构造 2. 用户模式构造 a.易失构造 在一个简单数据类型的变量上执行原子性读或写操作 VolaileWrite 强制address中的值在调用时写入,除此之外,按照源 ...
- 单例模式C#
首先来明确一个问题,那就是在某些情况下,有些对象,我们只需要一个就可以了, 比如,一台计算机上可以连好几个打印机,但是这个计算机上的打印程序只能有一个, 这里就可以通过单例模式来避免两个打印作业同时输 ...
- CentOS 6.3 配置 yum
ContOS 配置yum:1.cd /etc/yum.repos.d2.创建个任意目录,将所有文件移动到创建的目录中,除了CentOS-Media.repo3.编辑CentOS-Media.repov ...
- .NET序员的成长之路
- C#的winform拼数字游戏
C#的winform拼数字游戏 声明:阅读了别人的代码学习修改而来,增加了美观度和游戏乐趣.(作者出处忘了不好意思) 程序截图 关键代码 using System; using System.Coll ...
- C#如何判断两个数组相等
/// <summary> /// 数组比较是否相等 /// </summary> /// <param name="bt1">数组1</ ...
- Careercup - Google面试题 - 4857362737266688
2014-05-04 00:10 题目链接 原题: Write a function return an integer that satisfies the following conditions ...
- android 自定义ratingbar 图片显示不全的解决方案
在res/style中自定义评分条: <!-- 自定义评分条 --> <style name="roomRatingBar" parent="@andr ...
- Ubuntu C++环境支持
问题描述: 在Ubuntu中默认安装有gcc,但是只能编辑C程序,现在希望添加C++环境支持 问题解决: 首先是配置gcc,在ubuntu安装完成已经有gcc了(gcc ...