Using SVG to clip (or mask) a DIV

可紊 提交于 2019-12-12 23:43:28

问题


I've googled a lot and I've just given up, so I'll turn to the experts out there to see if someone can help me in my quest.

I've got a logo converted to .SVG through illustrator.

My objective is to use that logo to clip (or mask if you prefer) an entire div so that just a small part of it shows through and you can see the background.

I decided to go the .SVG way since I want to create this website as a full scalable experience, and thus a .png would not work accurately from full HD resolutions to 1024x768.

So firstly I would like to know how to clip a Div and at the same time how to "inverse clip" so that instead of just showing that part of the div it would show everything but it.

I'll be eagerly awaiting your answers as I really need them...

Thank you in advance.


回答1:


If I understood you correctly (and I'm not sure about that), you want to show 'everything in the background that fits the shape of your logo', is that correct? If though, what about 'inverting' your logo, making itself transparent and give the background a neutral color like black or white or something. Then you could put two divs upon each other, with the top being your Logo.

I created a fiddle to show you what I mean: http://jsfiddle.net/ds82/R4rBH/2/

Der circle is the logo and it's transparent inside and outside the blue line and it's a svg. Hope that is what you want.




回答2:


I don't think you are going to be able to do that. I once saw a plugin and a generator like this, though I think that that is probably not your best bet.

I would incorporate whatever text you wanted to clip in the svg which I'm sure is easier to do than finding a way for your html to interact properly with the svg.




回答3:


Well since I couldn't do it through .svg I ended up just using a .png where everything is black and my Logo is transparent. Kind of sad that I couldn't find the answer though...




回答4:


Basically what you want to do works only in Firefox at the moment. The way is to define the correct <mask> element in SVG and then apply it via CSS:

#content {
  mask: url(remote.svg#logo-mask);
}

(or, if you embedded the SVG:)

#content {
  mask: url(#logo-mask);
}


来源:https://stackoverflow.com/questions/10286576/using-svg-to-clip-or-mask-a-div

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!