模态框:

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. Java Collection.Set

    package 集合; /** * Set不包含重复元素 存储顺序和取出数据不一样 * * HashSet:它不保证set的迭代顺序,特别是它不保证该顺序恒久不变 * 底层是哈希表结构的 * Link ...

  2. 【转载】Web 研发模式演变

    一.简单明快的早期时代 可称之为 Web 1.0 时代,非常适合创业型小项目,不分前后端,经常 3-5 人搞定所有开发.页面由 JSP.PHP 等工程师在服务端生成,浏览器负责展现.基本上是服务端给什 ...

  3. 项目搭建系列之二:SpringMVC框架下配置MyBatis

    1.什么是MyBatis? MyBatis是一个支持普通SQL查询,存储过程和高级映射的优秀持久层框架.MyBatis消除了几乎所有的JDBC代码和参数的手工设置以及对结果集的检索封装.MyBatis ...

  4. JS文本中间显示省略号

    众所周知,文本溢出显示省略号用CSS就可以: 单行文本: white-space: nowrap; text-overflow: ellipsis; overflow: hidden; display ...

  5. <form> 标签的 enctype 属性

    值 描述 application/x-www-form-urlencoded 在发送前编码所有字符(默认) multipart/form-data 不对字符编码.在使用包含文件上传控件的表单时,必须使 ...

  6. 在Windows 7 上安装 Mapnik

    环境: 1.Windows 7_64位 2.Python 2.7_32位 步骤: 1.下载 Mapnik SDK   http://mapnik.org/download/  我下载的是  Windo ...

  7. 【MATLAB】R2017b两个镜像文件如何安装

    1.采用DEAMON TOOLS加载镜像1. 2.当安装过程中弹出[请插入DVD2]时,在原来的盘符上面右键点击[装载],选择DVD2的镜像文件.在安装程序处选择[继续]即可正常安装.

  8. Android学习——Fragment与Activity通信(二)

    接下来就要到Fragment向Activity传输数据了.主要的思路,就是在Fragment中创建一个回调接口,利用该回调接口实现Fragment向Activity传输数据的功能. 回调函数(接口) ...

  9. 【css基础】html图片右上角加上删除按钮

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  10. linux下修改apt下载源

    很多时候使用apt install命令会出现Unable to fetch somearchives的错误,我们需要运行以下apt update,可是经常会出现下载速度很慢的情况 这里就记一下将apt ...