html、css和js原生写一个模态弹出框,顺便解决父元素半透明子元素不透明效果
模态框:
html部分:
<!-- 按钮 -->
<button id="box" onclick="pop_box()">弹出框</button>
<!-- 弹出模态框 -->
<div class="div-container" id="div-container" style="display: none;">
<div class="div-child-container">
<div class="div-child">
<span>hhhhh</span>
<div class="my-btn">
<button id="cancleBtn" onclick="cancle()">取消</button>
<button id="confrim" onclick="confrim()">确认</button>
</div>
</div>
</div>
</div>
css部分:
<style type="text/css">
#box{
width: 80px;
height: 40px;
background: #fd7430;
border:none;
border-radius: 5px;
outline: none;
color: #fff;
} .div-container{
position: fixed;
top: 0%;
width: 100%;
height: 100%;
z-index:;
background: rgba(0,0,0,0.5) !important;/* 兼容ie几不知道,好像ie5 */
background:#000;
filter:Alpha(opacity=60);
}
/*设置div-child的父元素主要是将要此元素的父元素透明特性继承过来,故div-child不会半透明,而是不透明,解决了父元素透明,子元素也透明的bug */
.div-child-container{
position: relative;
width: 400px;
height: 200px;
margin: auto;
top: 30%;
background: #fff;
z-index:; /*z-index要放在父元素之上 */
} .div-child{
width: 400px;
height: 200px;
margin: auto;
background: #fff;
z-index:; /*z-index要放在父元素之上 */
text-align: center;
} .div-child span{
position: relative;
top: 40px;
} .div-child .my-btn{
margin-top: 80px;
}
.div-child .my-btn button{
width: 80px;
height: 40px;
background:#fd7430;
border: none;
border-radius: 5px;
color: #fff;
outline: none;
} .div-child .my-btn button:first-child(){
margin-right: 20px;
}
</style>
JavaScript:
<script type="text/javascript">
/*按钮弹出模态框*/
function pop_box(){
var container = document.getElementById('div-container');
container.style.display="block";
} /*取消事件*/
function cancle(){
var container = document.getElementById('div-container');
container.style.display="none";
} /*确认事件,因为现在没有确认事件,就将弹出框隐藏*/
function confrim(){
var container = document.getElementById('div-container');
container.style.display="none";
}
</script>
如有疑问,可留言!

html、css和js原生写一个模态弹出框,顺便解决父元素半透明子元素不透明效果的更多相关文章
- 玩转Bootstrap(JS插件篇)-第1章 模态弹出框 :1-3 模态弹出框
模态弹出框(Modals) 这一小节我们先来讲解一个“模态弹出框”,插件的源文件:modal.js. 右侧代码编辑器(30行)就是单独引入 bootstrap 中发布出的“modal.js”文件. 样 ...
- UIPresentationController - iOS自定义模态弹出框
参考: https://developer.apple.com/library/archive/featuredarticles/ViewControllerPGforiPhoneOS/Definin ...
- 玩转Bootstrap(JS插件篇)-第1章 模态弹出框 :1-4 模态弹出框--结构分析
模态弹出框--结构分析 Bootstrap框架中的模态弹出框,分别运用了“modal”.“modal-dialog”和“modal-content”样式,而弹出窗真正的内容都放置在“modal-con ...
- 玩转Bootstrap(JS插件篇)-第1章 模态弹出框 :1-2 动画过渡
动画过渡(Transitions) 这一小节我们先来讲“动画过渡(Transitions)”这个插件的使用,源文件:transition.js Bootstrap框架默认给各个组件提供了基本动画的过渡 ...
- Bootstrap模态弹出框
前面的话 在 Bootstrap 框架中把模态弹出框统一称为 Modal.这种弹出框效果在大多数 Web 网站的交互中都可见.比如点击一个按钮弹出一个框,弹出的框可能是一段文件描述,也可能带有按钮操作 ...
- bootstrap中的modal 模态弹出框不能放在 form_for里面,一弹出modal会自动submit掉form
bootstrap中的modal 模态弹出框不能放在 form_for里面,一弹出modal会自动submit掉form
- 玩转Bootstrap(JS插件篇)-第1章 模态弹出框 :1-1导入JavaScript插件
导入JavaScript插件 Bootstrap除了包含丰富的Web组件之外,如前面介绍的下拉菜单.按钮组.导航.分页等.他还包括一些JavaScript的插件. Bootstrap的JavaScri ...
- [Js插件]使用JqueryUI的弹出框做一个“炫”的登录页面
引言 查看项目代码的时候,发现项目中用到JqueryUi的弹出框,可拖拽,可设置模式对话框,就想着使用它弄一个登录页面. 弹出框 在Jquery Ui官网可定制下载弹出框,下载和弹出框下载相关的js文 ...
- bootstrap学习--模态弹出框modals轮子
1.点击按钮型 <link rel="stylesheet" href="lib/bootstrap/css/bootstrap.min.css"> ...
随机推荐
- 【linux】dpkg 命令使用说明
dpkg是一个debian包管理工具.能够对包进行安装.卸载.获取信息等操作.用法: 安装(解包并配置): dpkg -i package_file dpkg --ins ...
- [转]ASP.NET Core Exception Filters and Resource Filters
本文转自:https://damienbod.com/2015/09/30/asp-net-5-exception-filters-and-resource-filters/ This article ...
- BlackLowKey主题CSS
/* Minification failed. Returning unminified contents. (151,61): run-time error CSS1062: Expected se ...
- Hibernate中的一对一注解配置
Card类 package cn.OneToOne2017109.entity; import javax.persistence.*; /** * Created by YSS on 2017/10 ...
- 数组和矩阵(3)——Next Greater Element I
https://leetcode.com/problems/next-greater-element-i/#/description You are given two arrays (without ...
- 从零开始的全栈工程师——html篇1
全栈工程师也可以叫web 前端 H5主要是网站 app 小程序 公众号这一块 HTML篇 html(超文本标记语言,标记通用标记语言下的一个应用.) “超文本”就是指页面内可以包含图片.链接,甚至音乐 ...
- 使用cookie实现只出现一次的广告代码效果
我们上网经常会遇到第一次需要登录而之后不用再登录的网站的情况,其实是运用了Cookie 存储 web 页面的用户信息,Cookie 以名/值对形式存储,当浏览器从服务器上请求 web 页面时, 属于该 ...
- jQuery小测验
1.在div元素中,包含了一个<span>元素,通过has选择器获取<div>元素中的<span>元素的语法是? 提示使用has() $(div:has(span) ...
- iOS Touch ID 简易开发教程
转自:NsstringFromName 支持系统和机型 iOS系统的指纹识别功能最低支持的机型为iPhone 5s,最低支持系统为iOS 8,虽然安装iOS 7系统的5s机型可以使用系统提供的指纹解锁 ...
- SharePoint 2013 - Add-ins
1. App Web & Host Web The special website to which the app is deployed is called an App Web. The ...