今天看到一个纯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模态框的更多相关文章

  1. 使用基于关系的选择器和伪类选择器创建纯CSS无JavaScript的鼠标移动到上面即可显示的下拉菜单

    html代码: <div class="menu-bar"> <ul> <li> <h3 class="text-warning ...

  2. 大神写的一个纯CSS圆角框,膜拜!(支持IE9一下的低版本)

    留着提醒自己,底层才是最重要的,不要一直傻瓜的编程下去! <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN&q ...

  3. 【IE6的疯狂之八】链接伪类(:hover)CSS背景图片有闪动BUG

    IE6下链接伪类(:hover)CSS背景图片有闪动BUG,主要原因ie会再一次请求这张图片,或者说图片没被缓存. 例如: CSS代码 a:hover{background:url(imagepath ...

  4. 【转】链接伪类(:hover)CSS背景图片有闪动BUG

    来源:http://www.css88.com/archives/744 --------------------------------------------------------------- ...

  5. 【2048小游戏】——CSS/原生js爬坑之纯CSS模态对话框&游戏结束

    引言:2048小游戏的结束界面,使用纯CSS制作模态对话框,一般做模态对话框都会使用BootStrap自带的模态对话框组件方便使用,但在制作要运行在移动端的小项目时,就不能使用BootStrap,因为 ...

  6. 纯css单选框

    1.没有用bootstrap时: .has_sel,.un_sel{display:block; width:16px; height: 16px; border: 1px solid #B06A50 ...

  7. 好看css搜索框样式_分享8款纯CSS搜索框

    最简单实用的CSS3搜索框样式,纯CSS效果无需任何javascript,其中部分搜索框在点击的时候有动画特效,搜索框的应用也是比较普通的,效果如下: 设计网站大全https://www.wode00 ...

  8. 纯CSS气泡框实现方法探究

    气泡框(或者提示框)是网页中一种很常见的元素,大多用来展示提示信息,如下图所示: 拆分来看,形如这种气泡框无外乎就是一个矩形框+一个指示方向的三角形小箭头,要制作出这样的气泡框,如果解决了三角形小箭头 ...

  9. 利用animation和text-shadow纯CSS实现loading点点点的效果

    经常在网上看到loading状态时的点点点的动态效果,自己也用JS写了一个,思路是使用一个计数参数,然后在需要添加点的元素后面利用setInterval一个一个加点,当计数到3时,把点变为一个--写完 ...

随机推荐

  1. 第一节:从程序集的角度分析System.Web.Caching.Cache ,并完成基本封装。

    一. 揭开迷雾 1. 程序集准备 a.  需要给项目添加 System.Web 程序集. b.  需要给使用的地方添加两个引用. 2. 程序集探究      在对应的类中输入关键字 Cache,选中点 ...

  2. 消除 transition 闪屏

    .css { -webkit-transform-style: preserve-3d; -webkit-backface-visibility: hidden; -webkit-perspectiv ...

  3. UEditor百度编辑器,工具栏自定义添加一个普通按钮

    根据网上前辈提供的,还真的不错,下面也整理一下 添加一个名叫“macros”的普通按钮在工具栏上: 第一步:找到ueditor.config.js文件中的toolbars数组,增加一个“macros” ...

  4. EntityFramework用法探索(八)事务处理

    使用 前文中描述的Retail示例 ,在Customer对象的Mapping中设置Name属性:我们构造一个有效的Customer对象,再构造一个无效的Name属性为空的对象. DomainModel ...

  5. Python之print(args)与sys.stdout.write(string)使用总结

    一.sys.stdout.write(string) import sys; # sys.stdout.write(): # 1.默认不换行 # 2.参数必须是字符串 # demo 01 x = &q ...

  6. android 常见分辨率与DPI对照表

    分辨率对应DPI ldpi  QVGA (240×320) mdpi  HVGA (320×480) hdpi  WVGA (480×800),FWVGA (480×854) xhdpi  720P( ...

  7. Java获取资源路径——(八)

     获取文件资源有两种方式: 第一种是: 获取Java项目根目录开始制定文件夹下指定文件,不用类加载器(目录开始要加/) // 获取工程路径 System.out.println(System.getP ...

  8. ubuntu14.04 安装Kdevelop 进行ROS开发

    1. 安装gcc sudo apt-get build-dep gcc sudo apt-get install build-essential  2. 安装Kdevelop sudo apt-get ...

  9. ROS 错误之 [rospack] Error: package 'beginner_tutorials' not found

    ubuntu 下面情况处理 $ cd $gedit .bashrc 再后面加入两行 source /opt/ros/indigo/setup.bash source /home/lv/catkin_w ...

  10. EXT3.3.1在IE9 IE10click事件 失效怎么解决

    各位Ext君有福了. var treePanel = new Ext.tree.TreePanel({ id:'treePanel_'+(menuIndex++),//让菜单id可控 title: t ...