Using CSS Clip with percentage

前端 未结 4 2076
予麋鹿
予麋鹿 2021-02-19 05:28

I\'m trying to display only the top half of an image and the bottom half of the same image in 2 separate divs.

I\'ve tried with the CSS property clip, but i

4条回答
  •  悲&欢浪女
    2021-02-19 06:14

    Sorry that I don't have enough reputation to write a comment.

    There's absolutely a solution without JS.

    All you need to do is

    1. Create an svg clipPath, which allows you define whatever path you want.
    2. Set clipPathUnits="objectBoundingBox" for responsive clip path, which allows the usage of percentage path definition
    3. Apply the clipPath in your css code.

      #your-element {
         clip-path: url(#clipPathId);
      }
      

    If you want more information, please refer this answer https://stackoverflow.com/a/28312070/5692151

提交回复
热议问题