目录结构:
代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>关闭小广告</title>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
#qe_code {
width: 180px;
height: 160px;
position: relative;
/* 居中显示 */
margin: 15px auto;
}
#qe_code img{
position: absolute;
/* 靠右 */
right: 0;
}
#qe_code #close {
position: absolute;
width: 18px;
height: 18px;
/* 水平垂直居中 */
text-align: center;
line-height: 18px;
cursor: pointer;
border: 1px solid #e0e0e0;
color: #666;
}
</style>
</head>
<body>
<div id="qe_code">
<img src="./images/tb.png">
<span id="close">X</span>
</div>
<script>
var closeSpan = document.getElementById("close");
var qe_code = document.getElementById("qe_code");
closeSpan.onclick = function() {
// 点击span,让整个div盒子消失
qe_code.style.display = "none";
}
</script>
</body>
</html>
效果: