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>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Arial', sans-serif;
            min-height: 100vh;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            position: relative;
            overflow: hidden;
            background-color: #f5f5f5;
        }

        /* 花格纹理背景 */
        body::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: 
                linear-gradient(45deg, #e0e0e0 25%, transparent 25%) -50px 0,
                linear-gradient(-45deg, #e0e0e0 25%, transparent 25%) -50px 0,
                linear-gradient(45deg, transparent 75%, #e0e0e0 75%),
                linear-gradient(-45deg, transparent 75%, #e0e0e0 75%);
            background-size: 100px 100px;
            z-index: -1;
            opacity: 0.6;
        }

        /* 添加第二层纹理增加深度 */
        body::after {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: 
                linear-gradient(45deg, rgba(200, 200, 200, 0.3) 25%, transparent 25%) 0 0,
                linear-gradient(-45deg, rgba(200, 200, 200, 0.3) 25%, transparent 25%) 0 0,
                linear-gradient(45deg, transparent 75%, rgba(200, 200, 200, 0.3) 75%),
                linear-gradient(-45deg, transparent 75%, rgba(200, 200, 200, 0.3) 75%);
            background-size: 200px 200px;
            z-index: -1;
            opacity: 0.4;
        }

        .content {
            background-color: rgba(255, 255, 255, 0.9);
            padding: 40px;
            border-radius: 15px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            text-align: center;
            max-width: 800px;
            margin: 20px;
            backdrop-filter: blur(5px);
            border: 1px solid rgba(255, 255, 255, 0.3);
        }

        h1 {
            font-size: 2.5rem;
            margin-bottom: 20px;
            color: #333;
            position: relative;
            display: inline-block;
        }

        h1::after {
            content: '';
            position: absolute;
            bottom: -10px;
            left: 0;
            width: 100%;
            height: 3px;
            background: linear-gradient(90deg, #ff9a9e, #fad0c4);
            border-radius: 3px;
        }

        p {
            font-size: 1.1rem;
            line-height: 1.6;
            color: #555;
            margin-bottom: 30px;
        }

        .special-link {
            display: inline-block;
            padding: 12px 30px;
            background: linear-gradient(45deg, #ff9a9e, #fad0c4);
            color: white;
            text-decoration: none;
            border-radius: 30px;
            font-weight: bold;
            transition: all 0.3s ease;
            box-shadow: 0 4px 15px rgba(255, 154, 158, 0.4);
            position: relative;
            overflow: hidden;
        }

        .special-link:hover {
            transform: translateY(-3px);
            box-shadow: 0 8px 25px rgba(255, 154, 158, 0.6);
        }

        .special-link::before {
            content: '';
            position: absolute;
            top: 0;
            left: -100%;
            width: 100%;
            height: 100%;
            background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
            transition: all 0.5s;
        }

        .special-link:hover::before {
            left: 100%;
        }

        /* 动画效果 */
        @keyframes float {
            0%, 100% {
                transform: translateY(0);
            }
            50% {
                transform: translateY(-10px);
            }
        }

        .floating {
            animation: float 4s ease-in-out infinite;
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            h1 {
                font-size: 2rem;
            }
            
            p {
                font-size: 1rem;
            }
            
            .content {
                padding: 30px 20px;
            }
        }
    </style>
</head>
<body>
    <div class="content floating">
        <h1>CSS3 花格纹理背景</h1>
        <p>这个页面使用纯CSS3创建了精美的花格纹理背景效果,无需任何图片。<br>通过多重线性渐变和巧妙的背景定位实现了这种视觉上令人愉悦的图案。</p>
       
    </div>

    <script>
        // 添加简单的交互效果
        document.addEventListener('mousemove', function(e) {
            const x = e.clientX / window.innerWidth;
            const y = e.clientY / window.innerHeight;
            
            document.body.style.setProperty('--x', x);
            document.body.style.setProperty('--y', y);
            
            const content = document.querySelector('.content');
            content.style.transform = `translate(${x * 10 - 5}px, ${y * 10 - 5}px)`;
        });
    </script>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值