JAVASCRIPT
VUE
REACT
NODE
ES6
TYPESCRIPT

设置多个渐变

2023. 10. 10    

Css和Js设置多个渐变

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            overflow: hidden;
            width: 100px;
            height: 100px;
            border-radius: 50%;
            border: 1px solid #000;
        }

        .stacked-radial {
            background:
                radial-gradient(circle at 50% 0, rgba(255, 211, 0, 0.3), rgba(255, 0, 0, 0) 70.71%),
                radial-gradient(circle at 6.7% 75%, rgba(0, 0, 255, 0.3), rgba(0, 0, 255, 0) 70.71%),
                radial-gradient(circle at 93.3% 75%, rgba(0, 255, 0, 0.3), rgba(0, 255, 0, 0) 70.71%);

        }

        .stacked-linear {
            background:
                linear-gradient(217deg, rgba(255, 0, 0, 0.8), rgba(255, 0, 0, 0) 70.71%),
                linear-gradient(127deg, rgba(0, 255, 0, 0.8), rgba(0, 255, 0, 0) 70.71%),
                linear-gradient(336deg, rgba(0, 0, 255, 0.8), rgba(0, 0, 255, 0) 70.71%);
        }
    </style>
</head>

<body>
    <div class="stacked-radial"></div>
    <div class="stacked-linear"></div>

    <div id="wrap"></div>
    <div id="wrapL"></div>
</body>
<script>
    let wrap = document.getElementById('wrap')
    let wrapL = document.getElementById('wrapL')
    wrap.style.background = `
        radial-gradient(circle at 50% 0, rgba(255, 211, 0, 0.3) 0, rgba(255, 0, 0, 0) 70.71%),
        radial-gradient(circle at 6.7% 75%, rgba(0, 0, 255, 0.3) 0, rgba(255, 0, 0, 0) 70.71%),
        radial-gradient(circle at 93.3% 75%, rgba(0, 255, 0, 0.3) 0, rgba(255, 0, 0, 0) 70.71%)
        `
    wrapL.style.background = `
        linear-gradient(217deg, rgba(255, 211, 0, 0.3) 0, rgba(255, 0, 0, 0) 70.71%),
        linear-gradient(127deg, rgba(0, 0, 255, 0.3) 0, rgba(255, 0, 0, 0) 70.71%),
        linear-gradient(336deg, rgba(0, 255, 0, 0.3) 0, rgba(255, 0, 0, 0) 70.71%)
        `    
</script>

</html>

浏览器脱机调试接口