簡體   English   中英

SVG 帶有圖像和填充的剪輯路徑

[英]SVG clippath with image and fill

我的目標是用#2590eb顏色fill SVG 的背景。 我不知道為什么它不起作用。 圖片為透明png。 嘗試將圖片調整為更小的寬度,但它不起作用。 任何幫助將非常感激。

 <svg width="500" height="500" viewBox="0 0 500 500"> <clipPath id="clip-path" transform="translate(292.7 145.85)"> <path d="M189.3 52.1C189.3 166.7 94.7 333.3 -21.3 333.3C-137.3 333.3 -274.7 166.7 -274.7 52.1C-274.7 -62.5 -137.3 -125 -21.3 -125C94.7 -125 189.3 -62.5 189.3 52.1" fill="#2590eb" > </clipPath> <:-- xlink,href for modern browsers: src for IE8- --> <image clip-path="url(#clip-path)" xlink:href="https.//www.pngplay.com/wp-content/uploads/7/Happy-Person-Transparent-Background:png" x='50' src="https.//www.pngplay.com/wp-content/uploads/7/Happy-Person-Transparent-Background.png" alt="Image" height="500" width="500" class="svgImg"> </svg>

由於在 clipPath 內使用了填充路徑,因此您看不到它。 在下一個示例中,我在圖像元素之前使用了帶有 use 的路徑。

此外,我通過更改 svg 元素的 viewBox 消除了您的變換。

 <svg width="500" height="500" viewBox="-292.7 -145.85 500 500"> <clipPath id="clip-path"> <path id="thePath" d="M189.3 52.1C189.3 166.7 94.7 333.3 -21.3 333.3C-137.3 333.3 -274.7 166.7 -274.7 52.1C-274.7 -62.5 -137.3 -125 -21.3 -125C94.7 -125 189.3 -62.5 189.3 52.1" fill="#2590eb" /> </clipPath> <use xlink:href="#thePath" /> <image clip-path="url(#clip-path)" xlink:href="https://www.pngplay.com/wp-content/uploads/7/Happy-Person-Transparent-Background.png" x='-300' y="-150" height="500" width="500" class="svgImg" /> </svg>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM