css实现背景图片渐变过渡,视觉差

1. 背景图片过渡

background: url('http://xxx.jpg'), linear-gradient(to bottom, rgba(6, 22, 27, 1.0) 85%, rgba(243, 243, 243, 1.0) 100%);

2. 背景图片固定,实现视觉差效果

background-attachment: fixed;

问题: 在小程序真机中不起作用

解决方式:

    .header::before {
        content: '';
        // display: block;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 500rpx;
        background: linear-gradient(to bottom, rgba(255, 255, 255, 0) 20%, rgba(243, 243, 243, 1.0) 100%), url('http://xxx.jpg');
        background-size: contain;
        background-repeat: no-repeat;
    }

    .header {
        padding-top: 380rpx;
        width: 100%;
        position: relative;
            // background: linear-gradient(to bottom, rgba(255, 255, 255, 0) 20%, rgba(243, 243, 243, 1) 100%), url('https://img.jszero.cn/picgo/233cf0f156538fa06510f802e0c6caa5.jpg');
           // background-attachment: fixed;
           // background-size: contain;
           // background-repeat: no-repeat;
    }

     .main{
        position: relative;
        background-color: #f5f5f5;
     }

实现效果:


image.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容