M
M
Michael R.2018-02-13 15:37:07
css
Michael R., 2018-02-13 15:37:07

Correct positioning of svg polygon?

Hello!
I created a svg polygon triangle, now the question arose, how to correctly drop it in the center of the image?

<img src="https://image.freepik.com/free-photo/shiny-night-city_1127-8.jpg" alt="">
<svg>
 <defs>
  <clipPath id="clipping">
   <polygon points="0 0,300 0,150 300">
   </polygon>
  </clipPath>
 </defs>
</svg>

img
{
    max-width: 100%;
    clip-path: url(#clipping);
}

At the output, we get the following:
5a82d88c087de350612259.png
Ideally, set the position of the triangle in %, relative to the image, for example, in the center - 50% 50%.
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kovalsky, 2018-02-13
@Mike_Ro

Why do you need SVG? You can put a mask on simply with clip-path :

img {
  clip-path: polygon(0% 0%, 100% 0%, 50% 100%);
}

By the way, look at clippy

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question