Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Understanding the CSS Clip Property
Preethi⚡
Preethi⚡

Posted on

     

Understanding the CSS Clip Property

I’m pretty sure some of you may be not aware of CSS clip property. since it’s probably the less used property in the world. It’s no big deal guys. I can't wait, get this show on the road🎉.


clip property define crop the portion of an element you want to show. Exactly like,"crop" an image by a single CSS property without ask help to JS plugins. It's really surprising.

Image description

Probably, css clip property having some limitation. It's only working on position: absolute; or position: fixed;. It won’t work with relative or static positioning.

Though we can play around withclip property. start to learn clip property from syntax.

.element{position:absolute;clip:rect(110px,160px,170px,60px);}
Enter fullscreen modeExit fullscreen mode

Syntax seems little bit weird. Chill, it's still interesting. Just go through following code,

clip:rect(<top>,<right>,<bottom>,<left>);
Enter fullscreen modeExit fullscreen mode

Your guessing is right🥳. Above syntax seems similar tomargin orpadding shortcut. But, There is a difference in taking of value.

Now pay attention. Both the top and the bottom values define the offsetfrom the top border and the left and right values define the offsetfrom the left border.

Image description

I find best illustration for how clip property take values from above image. It definitely make sense to you. Hey still with me, I will show you an codepen demo(specially for your patience😍).

Congratulations🎉🎉, you reached the climax of this blog and Please execuse me, I ended up with one more bonus info.

The clip property accepts only three different values:

auto: this is the default behavior. Setting clip to auto is the same thing as not using clip at all.
inherit: well, it inherits the clip value from its parent.
a shape function: Currently only rect() exists.

Remember avoid usage of % inclip path, It's not working. Need to handle consciously.

Hope, Now you get familire withclip property. Hey Ninja🐱‍👤🐱‍👤,Thanks for reading!!. If you love it or you play around withclip property in experimentally, comment below.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Frontend Engineer | Working with design system
  • Location
    India
  • Education
    B.E Computer Science and Engineering
  • Joined

More fromPreethi⚡

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp