<style>
.box {
position: relative;
width: 1000px;
height: 200px;
background-color: pink;
margin: 100px auto;
text-align: center;
font-size: 50px;
line-height: 200px;
font-weight: 700;
}
.close {
position: absolute;
right: 20px;
top: 10px;
width: 20px;
height: 20px;
background-color: skyblue;
text-align: center;
line-height: 20px;
font-size: 16px;
cursor: pointer;
}
</style>
<div class="box">
我是广告
<div class="close">X</div>
</div>
<script>
// 1.获取 x 按钮与 box 盒子
const closebox = document.querySelector('.close')
const box = document.querySelector('.box')
// 2.需要给 x 按钮注册事件,鼠标点击事件
closebox.addEventListener('click', function () {
// 3.让 box 盒子隐藏, css 属性: display:none
box.style.display = 'none'
})
</script>