用HTML+CSS+JS,写一个公告提示框,警告窗,广告窗(可关闭)

效果图:

70b3837a035d4b49b75e7ee9f7e43a92.png

 HTML:

    <div class="box">
        <h2>标题</h2>
        <p>文本</p>
        <div class="box2">X</div>
    </div>

CSS:

    ​        .box{
            position: relative;
            width: 300px;
            height: 150px;
            background-image: linear-gradient(
                #547ad4,
                #7954df
            );
            border-radius: 20px;
            color: #ffffff;
            text-align: center;
        }
        .box2{
            position: absolute;
            right: 10px;
            top: 10px;
            width: 30px;
            height: 30px;
            background-color: #fff;
            border-radius: 50%;
            line-height: 30px;
            text-align: center;
            color: #000;
        }

​​​​​​JS:

const box=document.querySelector('.box')
const box2=document.querySelector('.box2')
box2.addEventListener('click',function(){
        box.style.display='none'
 })

全部代码:

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>

        .box{
            position: relative;
            width: 300px;
            height: 150px;
            background-image: linear-gradient(
                #547ad4,
                #7954df
            );
            border-radius: 20px;
            color: #ffffff;
            text-align: center;
        }
        .box2{
            position: absolute;
            right: 10px;
            top: 10px;
            width: 30px;
            height: 30px;
            background-color: #fff;
            border-radius: 50%;
            line-height: 30px;
            text-align: center;
            color: #000;
        }
    </style>
</head>
<body>
    <div class="box">
        <h2>标题</h2>
        <p>文本</p>
        <div class="box2">X</div>
    </div>

    <script>
        const box=document.querySelector('.box')
        const box2=document.querySelector('.box2')
        box2.addEventListener('click',function(){
            box.style.display='none'
        })
    </script>
</body>
</html>

 

⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️

制作不易,给个赞吧!

  • 11
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值