Using a mask for two elements to view a gradient behind those elements

18 views Asked by At

I am trying to create a thermometer which has a gradient from blue to red.

enter image description here

This needs to be dynamic, so I currently only have the outline as an image, and want to have the actual line inside change depending on the data I set.

    .temp-img{
        height: 64px;
        width: auto;
        position: relative;
        img{
            height: 100%;
            width: auto;
        }
        .gradient-wrap{
            border:1px solid green;
            height: 100%;
            bottom: 0;
            transform: translate(-50%, 0%);
            left: 50%;
            position: absolute;
            width: 100%;
            .line{
                position: absolute;
                background-color: red;
                width: 5px;
                height: 70%;
                border-radius: 5px;
                top: 50%;
                left: 50%;
                transform: translate(-50%, -50%);
            }
    
            .circle{
                position: absolute;
                background-color: red;
                bottom: 1px;
                width: 11.5px;
                height: 11.5px;
                border-radius: 100%;
                transform: translate(-50%, -50%);
                left: 50%;
            }
        }
    }
    <div class="temp-img">
        <img src="/img/klimaat/thermometer.svg" alt="Thermostaat">
        <div class="gradient-wrap">
            <div class="line"></div>
            <div class="circle"></div>
        </div>
    </div>

With the .gradient-wrap I can change the height, later I will make this dynamic.

How can I make sure this gradient:

background: linear-gradient(360deg, #CCD2F4 1.32%, #E61E14 184.88%);

Is only viewable through .line and .circle ?

I am guessing I need some css mask property, but after reading on the mask-image property I don't think that is what I need. What is the best solution for this?

0

There are 0 answers