弹出框也是前端里面经常使用的一个应用场景了,最开始想到的是用js实现这个效果,看到codepen上面有用css实现的。其实就是用到了css里面的一个:target选择器+visibility属性。
URL 带有后面跟有锚名称 #,指向文档内某个具体的元素。这个被链接的元素就是目标元素(target element)。:target 选择器可用于选取当前活动的目标元素。
示例代码:
<div class="container">
<a href="#popup" class="button">删除</a>
<div class="popup" >
<div class="popup-inner">
<div class="popup__text">
<h3>删除宝贝</h3>
<p>确定要删除该宝贝吗?</p>
<p><span><a href="javascript:void(0)">确定</a></span><span><a href="#">关闭</a></span></p>
</div>
<a href="#" class="popup__close">×</a>
</div>
</div>
</div>
scss代码:
$main-color: #9191E9;
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
html, body {
font-family: 'Raleway', sans-serif;
font-size: 16px;
}
.container {
background-color: $main-color;
display: flex;
align-items: center;
justify-content: center;
width: 100vw;
height: 100vh;
}
.button {
text-decoration: none;
font-size: .875rem;
}
.popup {
display: flex;
align-items: center;
justify-content: center;
position: fixed;
bottom: 0;
right: 0;
width: 100vw;
height: 100vh;
z-index: 2;
visibility: hidden;
&-inner {
background-color: #fff;
width: 400px;
height: 180px;
display: flex;
align-items: center;
position: relative;
bottom: -100vw;
right: -100vh;
transform: rotate(32deg);
transition: .64s ease-in-out;
}
&__text {
padding: 2rem;
h3 {
font-size: 1.2rem;
font-weight: 600;
margin-bottom: 1.2rem;
}
p {
font-size: .75rem;
margin-top: 1rem;
}
span {
display: inline-block;
padding: .42rem 1rem;
margin-right: .625rem;
a {
text-decoration: none;
}
&:first-child {
background-color: #52A0E5;
border: 1px solid #52A0E5;
a {
color: white;
&:hover {
text-decoration: underline;
}
}
}
&:last-child {
border: 1px solid grey;
a {
color: grey;
&:hover {
color: red;
text-decoration:underline;
}
}
}
}
}
&__close {
position: absolute;
right: 1.8rem;
top: 1.8rem;
font-size: 1.5rem;
color: grey;
text-decoration: none;
font-weight: 800;
}
&:target {
visibility: visible;
.popup-inner {
bottom: 0;
right: 0;
transform: rotate(0);
}
}
}
scss代码有点略长,核心就是.popup:target
与visibility
的结合,为什么不用opcaity和display呢?在这个场景中,opacity会影响html页面里的锚(这里面的popup遮挡到了body里面的a标签),而display不支持transition,并使transition失效。这里为了让弹出框不那么突兀地出现,加了一个小小的动画效果。
查看更多关于【css教程】的文章
jfinal框架页面找不到相关css,js文件404
在JFinalConfig中添加配置: @Overridepublic void configHandler(Handlers handlers) {handlers.add(new ContextPathHandler());}页面中添加:base href="${CONTEXT_PATH}/"/之前页面找不到资源,把tomcat工程路径去掉了(path=""),这样暂时解决了问题推荐
0评论2023-03-08576
移动端CSS底部固定和fixed定位在ios上的bug
fixed定位在ios上的bugcss三栏布局假设我们页面的 HTML 结构是这样: div class="wrapper"div class="content"!-- 页面主体内容区域 --/divdiv class="footer"!-- 需要做到 Sticky Footer 效果的页脚 --/div/div方法1.:absolute通过绝对定位处理应该是常见的
0评论2023-03-08624
css实现图片翻转 css使图片旋转
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"html xmlns="http://www.w3.org/1999/xhtml"headmeta http-equiv="Content-Type" content="text/h
0评论2023-03-08577
CSS3中的px,em,rem,vh,vw辨析 css3 vw
1、px:像素,精确显示2、em:继承父类字体的大小,相当于“倍”,如:浏览器默认字体大小为16px=1em,始终按照div继承来的字体大小显示,进场用于移动端 em换算工具:http://www.runoob.com/tags/ref-pxtoemconversion.html3、rem:与em类似,
0评论2023-03-08902
gulp自动化构建工具--自动编译less为css--学习笔记
1.安装 命令:npm install gulp-less 或者 cnpm install gulp-less2.编写文件 //获取gulpvar gulp = require('gulp')//获取gulp-less模块var less = require("gulp-less")//编译less//在命令行输入gulp less启动此任务gulp.task('less',function(){
0评论2023-03-08411
关于动画Animate.css的使用方法
首先贴个官网:https://daneden.github.io/animate.css/ 1、引入animate css文件 1 head2 link rel="stylesheet" href="animate.min.css"3 /head 2、给指定的元素加上指定的动画样式名div class="animated bounceOutLeft"/div 这里包
0评论2023-03-08673
selenium Firefox禁用js,css.falsh,缓存,设置请求头和代理ip
1 profile = FirefoxProfile() 2 #请求头 3 #profile.set_preference("general.useragent.override", util.http_agent_insert(xinhuaUtil.agent_path)) 4 # 激活手动代理配置(对应着在 profile(配置文件)中设置首选项) 5 profile.set_preference("network
0评论2023-03-08777
页面css样式找不到问题 页面css样式找不到问题怎么解决
出现了一个页面没有样式的问题:问题: 1.路径不对, 可以打开页面f12看样式是否找到 检查路径是否正确。 2.样式没引全或者没引对。查看引入的样式是否正确或缺少样式。 3.路径明明写对了却404找不到。可以试一试把${pageContext.request.context
0评论2023-03-08414
学习前端页面css定位 网页前端设计css
一、相对定位:absolute 相对定位是一个非常容易掌握的概念。如果对一个元素进行相对定位,它将出现在它所在的位置上。然后,可以通过设置垂直或水平位置,让这个元素“相对于”它的起点进行移动。position:relative;同时可以设置上下左右位置偏移;rela
0评论2023-03-08782
css-移动端模拟hover效果 css移动端适配
:hover 在移动端中,点击后一直处于hover状态,不会切换。为此解决:通过:active模拟!-- * @Author: lingxie * @Date: 2020-04-23 13:35:57 * @Descripttion: -- templatediv class="about"h1This is an about page/h1div class="btn-hole"按钮/div/div/templ
0评论2023-03-08409
css固定定位,不随滚动条滚动 css固定在底部
!DOCTYPE htmlhtml lang="en"headmeta charset="UTF-8"meta http-equiv="X-UA-Compatible" content="IE=edge"meta name="viewport" content="width=device-width, initial-scale=1.0"titleDocument/titlestyleb
0评论2023-03-08745
(转)JAVA中解决Filter过滤掉css,js,图片文件等问题
在加入过滤器时,会出现网页可以加载,但是网页中的js,css等文件无法加载的问题。因为在网页加载时,先将整个网页加载,然后加载网页中的js,css等文件,而在进行js,css文件加载时,会被过滤器过滤掉。因此在过滤器中加入一个对css,js等文件的判断,就可以
0评论2023-03-08794
CSS3 Flexbox轻松实现元素的水平居中和垂直居中
CSS3 Flexbox轻松实现元素的水平居中和垂直居中网上有很多关于Flex的教程,对于Flex的叫法也不一,有的叫Flexbox,有的叫Flex,其实这两种叫法都没有错,只是Flexbox旧一点,而Flex是刚出来不久的东西而已,为了方便说明,赶上新技术,下面我就把这种布局叫Fl
0评论2023-03-08774
css3多行文本溢出显示省略号… css3行超出省略号
.title {width: rem(210);overflow: hidden;text-overflow: ellipsis;display: -webkit-box;-webkit-line-clamp: 2;-webkit-box-orient: vertical;}
0评论2023-03-08638
模板文件引入css样式文件 word怎么把模板的样式加载进来
引用路径问题:相对路径和绝对路径相对路径:相对路口文件index.php设置绝对路径:从虚拟主机站点目录开始设置css样式文件引入图片,路径的设置相对地址:相对css文件本身设置①模板文件 引入css样式文件(css的相对路径可以相对index.php入口文件设置)index
0评论2023-03-08871