html+css实现一个弹出框

效果图如下:
弹出框实现了对浏览器窗口的水平垂直居中
html代码如下(命名为:dialog.html):

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <link rel="stylesheet" href="dialog.css" type="text/css">
    </head>
    <body>
        弹窗练习
        <div class="dialog">
            <p class="header">提示文字</p>
            <div class="footer">
                <button class="cancel">取消</button>
                <button class="confirm">确认</button>
            </div>
        </div>
    </body>
</html>

css代码如下(命名为:dialog.css):

body{
    background-color: rgba(0,0, 0, 0.8);/*设置透明度为0.8,以突出遮罩效果*/
}
.dialog{
    background-color: rgba(255,255, 255, 1);
    width: 20%;
    height: 100px;
    border-radius: 5px;
    z-index: 1;/*优先*/
    text-align: center;
    /* 实现对浏览器窗口的垂直居中 */
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%,-50%);
}
/* 弹出框的提示文字部分 */
.header{
    height: 60%;
    line-height: 60px;
    margin: 0 auto;
}
/* 弹出框的两个按钮部分 */
.footer{
    height: 40%;
    display: flex;
    flex-direction: row;
}
/* 取消和确认按钮的设置 */
.confirm,.cancel{
    outline: none;
    background-color: white;
    width: 50%;
}
.confirm{
    border-width: 1px 0px 0px 1px;
    border-bottom-right-radius:5px; 
}
.cancel{
    border-width: 1px 0px 0px 0px;
    border-bottom-left-radius:5px; 
}


  • 7
    点赞
  • 47
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值