ARTICLE AD BOX
I want to control linear-gradient based on an attribute value. My HTML:
<div class="percentage" data-percentage="50%"></div>My css:
.percentage { width: 100px; border: .1px solid; border-radius: 2px; font-size: 1rem; padding: 1px; background-clip: content-box; background-image: linear-gradient( to right, #cccc 50%, transparent 0% ); } .percentage::before { content: attr(data-percentage); }This works. What doesn't work is to control the linear-gradient with the attribute value:
background-image: linear-gradient( to right, #cccc attr(data-percentage), transparent 0% );So it seems accessing an attr() inside linear-gradient() isn't possible? How can I control the linear gradient based on the attribute value?
5991 gold badge6 silver badges23 bronze badges
This is possible but, unfortunately, it's not yet fully supported in Firefox or Safari as neither yet support the CSS type() function (compatibility, Can I Use):
References:
attr(). type().254k53 gold badges382 silver badges421 bronze badges
You can but only in limited browsers as of the time of writing (1/26) with the advanced attr() function. (CSS Units Level 5)
Chrome/Edge
116k13 gold badges168 silver badges186 bronze badges
Explore related questions
See similar questions with these tags.
