模态框:

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原生写一个模态弹出框,顺便解决父元素半透明子元素不透明效果的更多相关文章

  1. 玩转Bootstrap(JS插件篇)-第1章 模态弹出框 :1-3 模态弹出框

    模态弹出框(Modals) 这一小节我们先来讲解一个“模态弹出框”,插件的源文件:modal.js. 右侧代码编辑器(30行)就是单独引入 bootstrap 中发布出的“modal.js”文件. 样 ...

  2. UIPresentationController - iOS自定义模态弹出框

    参考: https://developer.apple.com/library/archive/featuredarticles/ViewControllerPGforiPhoneOS/Definin ...

  3. 玩转Bootstrap(JS插件篇)-第1章 模态弹出框 :1-4 模态弹出框--结构分析

    模态弹出框--结构分析 Bootstrap框架中的模态弹出框,分别运用了“modal”.“modal-dialog”和“modal-content”样式,而弹出窗真正的内容都放置在“modal-con ...

  4. 玩转Bootstrap(JS插件篇)-第1章 模态弹出框 :1-2 动画过渡

    动画过渡(Transitions) 这一小节我们先来讲“动画过渡(Transitions)”这个插件的使用,源文件:transition.js Bootstrap框架默认给各个组件提供了基本动画的过渡 ...

  5. Bootstrap模态弹出框

    前面的话 在 Bootstrap 框架中把模态弹出框统一称为 Modal.这种弹出框效果在大多数 Web 网站的交互中都可见.比如点击一个按钮弹出一个框,弹出的框可能是一段文件描述,也可能带有按钮操作 ...

  6. bootstrap中的modal 模态弹出框不能放在 form_for里面,一弹出modal会自动submit掉form

    bootstrap中的modal 模态弹出框不能放在 form_for里面,一弹出modal会自动submit掉form

  7. 玩转Bootstrap(JS插件篇)-第1章 模态弹出框 :1-1导入JavaScript插件

    导入JavaScript插件 Bootstrap除了包含丰富的Web组件之外,如前面介绍的下拉菜单.按钮组.导航.分页等.他还包括一些JavaScript的插件. Bootstrap的JavaScri ...

  8. [Js插件]使用JqueryUI的弹出框做一个“炫”的登录页面

    引言 查看项目代码的时候,发现项目中用到JqueryUi的弹出框,可拖拽,可设置模式对话框,就想着使用它弄一个登录页面. 弹出框 在Jquery Ui官网可定制下载弹出框,下载和弹出框下载相关的js文 ...

  9. bootstrap学习--模态弹出框modals轮子

    1.点击按钮型 <link rel="stylesheet" href="lib/bootstrap/css/bootstrap.min.css"> ...

随机推荐

  1. node.js之forEach

    forEach用法: var array1=[1,2,3]; array1.forEach(function(item,index){ console.log(item+'---'+index); } ...

  2. 从零开始编译属于你的FFmpeg

    一.前提: 编译FFmpeg可以是初学者,尤其是对C语言项目,Linux编译不熟悉的的初学者的一道门槛. 我曾经找过很多博客,文章,有些能编译成功,有些则不能.编译通过,能够运行也是云里雾里的.其实最 ...

  3. scss-!default默认变量

    在变量赋值之前, 利用!default为变量指定默认值. 也就是说,如果在此之前变量已经赋值,那就不使用默认值,如果没有赋值,则使用默认值. 代码实例如下: $content: "antzo ...

  4. 【数据库】6.0 MySQL入门学习(六)——MySQL启动与停止、官方手册、文档查询

    1.0 MySQL主要有四种启动方式:直接启动.安全启动.服务启动.多实例启动. 直接启动: 服务器启动: 安全启动(最常用): 多实例启动: 2.0如何获得MySQL帮助 2.1官方手册 下面提供百 ...

  5. Stage5--Python GUI编程TKinter

    Python图形库简要介绍 python提供了多个图形开发界面的库,几个常用Python GUI库如下: Tkinter: Tkinter模块("Tk 接口")是Python的标准 ...

  6. 基于ArcGIS的CAD数据向GIS数据转换方法(转)

    基于ArcGIS的CAD数据向GIS数据转换方法 1 CAD数据与ArcGIS数据介绍 地图数据来源多种多样,大多数使用的是计算机辅助设计软件(CAD)制作的数据,CAD软件制图自动化程度高,操作简单 ...

  7. Steps of source code change to executable application

    程序运行的整个过程,学习一下 源代码 (source code) → 预处理器 (preprocessor) → 编译器 (compiler) → 汇编程序 (assembler) → 目标代码 (o ...

  8. Mantis去掉登录界面的“注册一个新账号”链接

    Mantis1.1.2主界面提供了新账号注册功能,但是只能注册默认权限的帐号.不是很实用,那就干脆去掉吧. (1) 打开Mantis目录下的login_page.php和lost_pwd_page.p ...

  9. css加载是否会阻塞dom树渲染

    这里说的是头部引入css的情况 首先,我们都知道:css是由单独的下载线程异步下载的. 咱们先分析下css加载会影响什么,刚才的问题太笼统了,咱们需要细化一下. 会影响什么呢? 一个就是DOM树解析, ...

  10. 【Leetcode】【Easy】Balanced Binary Tree

    Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary ...