0
我試圖使用CSS內容attr
功能把一個SVG圈內百分比數字,像這樣:使用CSS ATTR()與風格的組成部分
content: attr(data-percent)%;
僞元素不會被渲染因爲Styled組件似乎無法在最後處理%
。如果我刪除它,它可以工作,但我希望數字顯示爲20%
,此格式對常規CSS有效。
有沒有我在這裏失蹤的東西,還是與圖書館的限制?
const Div = styled.div`
position: relative;
width: 100%;
height: 100%;
&:after {
content: attr(data-percent)%;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
`;
render() {
return (
<Div data-percent={20}>
<sgv viewBox="0 0 120 120">
<circle cx="60" cy="60" r="50" fill="none" strokeWidth="10" strokeLinecap="round"/>
</svg>
</Div>
);
}
完美,謝謝! –