CSS3 带图标的消息提示框

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CSS3 带图标的消息提示框</title>
    <style>
        /* 基础样式 */
        body {
            font-family: 'Arial', sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            background-color: #f5f5f5;
            margin: 0;
            padding: 20px;
        }
        
        /* 消息提示框容器 */
        .alert-container {
            width: 100%;
            max-width: 500px;
        }
        
        /* 消息提示框基础样式 */
        .alert {
            position: relative;
            padding: 15px 20px 15px 60px;
            margin-bottom: 15px;
            border-radius: 4px;
            color: #fff;
            font-size: 16px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            transition: all 0.3s ease;
            opacity: 0.9;
        }
        
        .alert:hover {
            opacity: 1;
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
        }
        
        /* 图标样式 */
        .alert:before {
            font-family: 'Font Awesome 5 Free';
            font-weight: 900;
            position: absolute;
            left: 20px;
            top: 50%;
            transform: translateY(-50%);
            font-size: 24px;
        }
        
        /* 不同类型的消息提示框 */
        .alert-success {
            background-color: #4CAF50;
            border-left: 5px solid #388E3C;
        }
        
        .alert-success:before {
            content: "\f058";
        }
        
        .alert-info {
            background-color: #2196F3;
            border-left: 5px solid #1976D2;
        }
        
        .alert-info:before {
            content: "\f05a";
        }
        
        .alert-warning {
            background-color: #FFC107;
            border-left: 5px solid #FFA000;
            color: #333;
        }
        
        .alert-warning:before {
            content: "\f071";
        }
        
        .alert-danger {
            background-color: #F44336;
            border-left: 5px solid #D32F2F;
        }
        
        .alert-danger:before {
            content: "\f057";
        }
        
        /* 关闭按钮 */
        .close-btn {
            position: absolute;
            right: 15px;
            top: 50%;
            transform: translateY(-50%);
            cursor: pointer;
            font-size: 20px;
            opacity: 0.7;
        }
        
        .close-btn:hover {
            opacity: 1;
        }
    </style>
    <!-- 引入Font Awesome图标库 -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
</head>
<body>
    <div class="alert-container">
        <div class="alert alert-success">
            操作成功!您的请求已提交。
            <span class="close-btn">&times;</span>
        </div>
        
        <div class="alert alert-info">
            提示信息:系统将于今晚进行维护。
            <span class="close-btn">&times;</span>
        </div>
        
        <div class="alert alert-warning">
            警告:您有未保存的更改。
            <span class="close-btn">&times;</span>
        </div>
        
        <div class="alert alert-danger">
            错误:无法完成请求,请重试。
            <span class="close-btn">&times;</span>
        </div>
    </div>
    
    <!-- 插入指定链接 -->
    <div style="text-align: center; margin-top: 30px;">
     
    </div>
    
    <script>
        // 添加关闭功能
        document.querySelectorAll('.close-btn').forEach(btn => {
            btn.addEventListener('click', function() {
                this.parentElement.style.opacity = '0';
                setTimeout(() => {
                    this.parentElement.style.display = 'none';
                }, 300);
            });
        });
    </script>
</body>
</html>

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值