css实现简单弹框

html-css010

css实现简单弹框,第1张

写一个简单的弹框

html:

<button onclick=""bombClick()" >点击弹框</button>

<div id="bombContain"></div>

<div id="bomb_div"></div>

css:

#bombContain{

z-index: 199412204822//z-index只有在定位元素上生效,默认值static是没有定位的

background-color:#000

opacity:0.6

top:0

left:0

width:100%

height:100%

position:fixed

display:none

}

#bomb_div{

z-index:199412204822

width:34%

height:450px

top:66px

left:36%

margin:0

padding:0

background-color:#fff

box-shadow:1px 1px 50px rgba(0,0,0,.3)

position:fixed

display:none

}

js:

function bombClick(){

$("#bombContain").css("display","block")

$("#bomb_div").css("display","block")

}

CSS部分

div{

width: 400px

height: 400px

border:1px solid red

float: left

}

body:hover .box{

display: block

}

.box{

width: 200px

height: 200px

background: red

display: none

}

html部分

<div  >

<div class="box">

</div>

</div>