伪类target实现纯css模态框
今天看到一个纯css模态框,觉得是很牛呀
看了下用了target伪类,
一直不知道有这么神奇的伪类
。。
用法是这样的,给模态框一个id,
<div id="pop" class="overlay">
然后通过锚链接的方法
<a class="button" href="#pop">Click!</a>
点击之后,伪类的css就能发生作用了
.overlay:target {
visibility: visible;
opacity: 1;
}
.overlay:target > .modal {
transform: translateY(30%) scale(0.9);
transition-timing-function: cubic-bezier(0.8, 0, 0, 1.5);
opacity: 1;
}
顺便把别人的源码发一下
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CSS模态框-jq22.com</title>
<style>
html, body {
height: 100%;
-webkit-font-smoothing: antialiased;
-webkit-tap-highlight-color: transparent;
} body {
margin: 0;
background-color: #FAFAFB;
color: slategrey;
} a.button {
text-decoration: none;
text-align: center;
text-shadow: 0 1px 0 #fff;
color: steelblue;
font-weight: 500;
padding: 8px 15px 8px 15px;
border: 1px solid rgba(26, 53, 71, 0.1);
border-radius: 4px;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
transition: .25s;
background: linear-gradient(white, ghostwhite);
}
a.button:hover {
border: 1px solid rgba(26, 53, 71, 0.2);
background: white;
} .wrapper {
width: 600px;
height: 100%;
margin: auto;
text-align: center;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
align-items: center;
justify-content: center;
} .overlay {
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(0, 0, 0, 0.7);
transition: opacity .5s;
visibility: hidden;
opacity: 0;
}
.overlay:target {
visibility: visible;
opacity: 1;
} .modal {
width: 20%;
position: relative;
margin: auto;
padding: 1.5rem;
background: #fff;
border-radius: 4px;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
transition: .5s;
opacity: 0;
}
.modal .content {
margin-top: 1rem;
}
.modal .content a {
max-width: 60%;
margin: auto;
display: block;
} .overlay:target > .modal {
transform: translateY(30%) scale(0.9);
transition-timing-function: cubic-bezier(0.8, 0, 0, 1.5);
opacity: 1;
} h2 {
text-align: center;
margin-top: 2rem;
} a.close {
position: absolute;
top: 15px;
left: 15px;
width: 22px;
height: 22px;
text-decoration: none;
text-align: center;
font-size: 20px;
line-height: 21px;
color: lightslategrey;
background-color: lightgrey;
border-radius: 50%;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
transition: .25s;
}
a.close:hover {
background-color: tomato;
color: white;
} </style>
</head>
<body>
<div class="wrapper">
<a class="button" href="#pop">Click!</a>
</div> <div id="pop" class="overlay">
<div class="modal">
<h2>Hey there!</h2>
<a class="close" href="#">×</a>
<div class="content">
So, here we are:<br/>
I am a pure (S)CSS Modal and work with the <strong>:target</strong> element.<br/><br/>
You can close me by clicking the x in the upper left corner or the button at the bottom.<br/><br/>
See you next time:)<br/><br/>
<a class="button" href="#">Close</a>
</div>
</div>
</div>
</body>
</html>
伪类target实现纯css模态框的更多相关文章
- 使用基于关系的选择器和伪类选择器创建纯CSS无JavaScript的鼠标移动到上面即可显示的下拉菜单
html代码: <div class="menu-bar"> <ul> <li> <h3 class="text-warning ...
- 大神写的一个纯CSS圆角框,膜拜!(支持IE9一下的低版本)
留着提醒自己,底层才是最重要的,不要一直傻瓜的编程下去! <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN&q ...
- 【IE6的疯狂之八】链接伪类(:hover)CSS背景图片有闪动BUG
IE6下链接伪类(:hover)CSS背景图片有闪动BUG,主要原因ie会再一次请求这张图片,或者说图片没被缓存. 例如: CSS代码 a:hover{background:url(imagepath ...
- 【转】链接伪类(:hover)CSS背景图片有闪动BUG
来源:http://www.css88.com/archives/744 --------------------------------------------------------------- ...
- 【2048小游戏】——CSS/原生js爬坑之纯CSS模态对话框&游戏结束
引言:2048小游戏的结束界面,使用纯CSS制作模态对话框,一般做模态对话框都会使用BootStrap自带的模态对话框组件方便使用,但在制作要运行在移动端的小项目时,就不能使用BootStrap,因为 ...
- 纯css单选框
1.没有用bootstrap时: .has_sel,.un_sel{display:block; width:16px; height: 16px; border: 1px solid #B06A50 ...
- 好看css搜索框样式_分享8款纯CSS搜索框
最简单实用的CSS3搜索框样式,纯CSS效果无需任何javascript,其中部分搜索框在点击的时候有动画特效,搜索框的应用也是比较普通的,效果如下: 设计网站大全https://www.wode00 ...
- 纯CSS气泡框实现方法探究
气泡框(或者提示框)是网页中一种很常见的元素,大多用来展示提示信息,如下图所示: 拆分来看,形如这种气泡框无外乎就是一个矩形框+一个指示方向的三角形小箭头,要制作出这样的气泡框,如果解决了三角形小箭头 ...
- 利用animation和text-shadow纯CSS实现loading点点点的效果
经常在网上看到loading状态时的点点点的动态效果,自己也用JS写了一个,思路是使用一个计数参数,然后在需要添加点的元素后面利用setInterval一个一个加点,当计数到3时,把点变为一个--写完 ...
随机推荐
- 〖C语言学习笔记 〗(一) HelloWorld
前言 本文为c基础入门学习笔记 正文 HelloWorld #include <stdio.h> //标准输出流 int main() //每种语言都有一个执行入口,main方法就是其一 ...
- Host is not allowed to connect to this MySQL server解决方法
在装有MySQL的机器上登录MySQL mysql -u root -p密码 执行use mysql; 执行update user set host = '%' where user = 'root' ...
- 三、内存管理单元---MMU
3.1 MMU介绍 3.1.1 MMU 特性 内存管理单元(Memory Management Unit)简称MMU,它负责虚拟地址到物理地址的映射,并提供硬件机制的内存访问权限检查.现在的多用户多进 ...
- log4j2 的使用
log4j2 是 log4j 的升级,更为方便,更为强大. log4j2.xml 的配置以及 log4j2的依赖包使用log4j2 并没有其他的依赖包,只是在使用log4j的情况下,需要别的进行桥接 ...
- 你真的懂 ajax 吗?
前言 总括: 本文讲解了ajax的历史,工作原理以及优缺点,对XMLHttpRequest对象进行了详细的讲解,并使用原生js实现了一个ajax对象以方便日常开始使用. damonare的ajax库: ...
- Python 入门基础16 -- ATM + 购物车
ATM + 购物车 1.需求分析 2.设计程序以及程序的架构 设计程序的好处: - 扩展性强 - 逻辑清晰 3.分任务开发 4.测试 黑盒: 白盒: 对程序性能的测试 5.上线运行 # Tank -- ...
- ANR异常及traces信息解析
Application Not Responding:默认情况下,在android中Activity的最长执行时间是5秒,BroadcastReceiver的最长执行时间则是10秒.超出就会提示应用程 ...
- 跟踪OceanLotus的新下载程序KerrDown
攻击的方法 两种方法将KerrDown下载器传递给目标.一个是使用带有恶意宏的Microsoft Office文档,另一个是包含带有DLL side-loading合法程序的RAR存档 .对于RAR存 ...
- linux源码Makefile详解(完整)
转自:http://www.cnblogs.com/Daniel-G/p/3286614.html 随着 Linux 操作系统的广泛应用,特别是 Linux 在嵌入式领域的发展,越来越多的人开始投身到 ...
- shiro设置session超时时间
系统默认超时时间是180000毫秒(30分钟) long timeout = SecurityUtils.getSubject().getSession().getTimeout(); System. ...