{"id":2502,"date":"2017-06-19T19:57:00","date_gmt":"2017-06-19T19:57:00","guid":{"rendered":"http:\/\/cssreset.com\/?p=2502"},"modified":"2017-06-19T19:57:00","modified_gmt":"2017-06-19T19:57:00","slug":"how-to-use-csss-clip-property","status":"publish","type":"post","link":"https:\/\/cssdeck.com\/blog\/how-to-use-csss-clip-property\/","title":{"rendered":"How to Use CSS&#8217;s Clip Property"},"content":{"rendered":"<p>CSS&#8217;s clip property can be used to change the size of an image, but in a different way than using the width and height properties would. The width and height elements are used to adjust the size and scale of an entire image, but the clip property just clips an image, so that it can fit within an particular element, even if the entire image isn&#8217;t actually showing. Essentially, it cuts the image off.<\/p>\n<p>Using the clip property is actually pretty easy, because it only takes one property : rect(top, right, bottom, left).<\/p>\n<p>This property is used to define the shape (it has to be rectangle) and the top, right, bottom, and left values (these values represent the coordinates that are meant to be clipped from the top-left corner of the element.<\/p>\n<p>The property doesn&#8217;t work if the overflow property is set to visible, and it also won&#8217;t work unless the position property of your image element is set to absolute. Make sure you have these two things in order before trying to apply the clip property to your image elements.<\/p>\n<p>If you want to see an example of how you&#8217;d use the clip property to clip an image, take a look at the CSS and the screenshot below.<\/p>\n<p>First, the CSS:<\/p>\n<pre>img{\r\n\u00a0 \u00a0position: absolute;\r\n\u00a0 \u00a0clip: rect(0, 160px, 200px, 0)\r\n}<\/pre>\n<p>There&#8217;s no need to set the overflow property to hidden, because hidden is the default value.<\/p>\n<p>The clipped image in the example above looks something like this:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-2503 aligncenter\" alt=\"Screen Shot 2017-05-21 at 3.22.15 PM\" src=\"https:\/\/cssdeck.com\/blog\/\/wp-content\/uploads\/2017\/05\/Screen-Shot-2017-05-21-at-3.22.15-PM.png\" width=\"338\" height=\"302\" srcset=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2017\/05\/Screen-Shot-2017-05-21-at-3.22.15-PM.png 338w, https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2017\/05\/Screen-Shot-2017-05-21-at-3.22.15-PM-300x268.png 300w, https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2017\/05\/Screen-Shot-2017-05-21-at-3.22.15-PM-180x160.png 180w\" sizes=\"(max-width: 338px) 100vw, 338px\" \/><\/p>\n<p>You might not be able to tell from the example, but the original image extended much farther to the right than this image does, and it has been clipped considerably thanks to the clip property. Now that you understand the basics of the clip property, it&#8217;s your turn to play around with it and see if you can really master it. The best way to fully understand how to use a property is to use it yourself in a real world context. Happy coding!<\/p>\n<div class=\"wp-socializer wpsr-share-icons \" data-lg-action=\"show\" data-sm-action=\"show\" data-sm-width=\"768\" ><h3>Share and Enjoy !<\/h3><div class=\"wpsr-si-inner\"><div class=\"wpsr-counter wpsrc-sz-32px\" style=\"color:#000\"><span class=\"scount\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"facebook,twitter,linkedin,pinterest,print,pdf\">0<\/span><\/span><small class=\"stext\">Shares<\/small><\/div><div class=\"socializer sr-popup sr-32px sr-circle sr-opacity sr-pad sr-count-1 sr-count-1\"><span class=\"sr-facebook\"><a rel=\"nofollow\" href=\"https:\/\/www.facebook.com\/share.php?u=\" target=\"_blank\"  title=\"Share this on Facebook\"  style=\"color: #ffffff\" ><i class=\"fab fa-facebook-f\"><\/i><span class=\"ctext\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"facebook\">0<\/span><\/span><\/a><\/span>\n<span class=\"sr-twitter\"><a rel=\"nofollow\" href=\"https:\/\/twitter.com\/intent\/tweet?text=%20-%20%20\" target=\"_blank\"  title=\"Tweet this !\"  style=\"color: #ffffff\" ><i class=\"fab fa-twitter\"><\/i><\/a><\/span>\n<span class=\"sr-linkedin\"><a rel=\"nofollow\" href=\"https:\/\/www.linkedin.com\/sharing\/share-offsite\/?url=\" target=\"_blank\"  title=\"Add this to LinkedIn\"  style=\"color: #ffffff\" ><i class=\"fab fa-linkedin-in\"><\/i><\/a><\/span>\n<span class=\"sr-pinterest\"><a rel=\"nofollow\" href=\"https:\/\/www.pinterest.com\/pin\/create\/button\/?url=&amp;media=&amp;description=\" target=\"_blank\"  title=\"Submit this to Pinterest\"  style=\"color: #ffffff\" data-pin-custom=\"true\"><i class=\"fab fa-pinterest\"><\/i><span class=\"ctext\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"pinterest\">0<\/span><\/span><\/a><\/span>\n<span class=\"sr-print\"><a rel=\"nofollow\" href=\"https:\/\/www.printfriendly.com\/print?url=\" target=\"_blank\"  title=\"Print this article \"  style=\"color: #ffffff\" ><i class=\"fa fa-print\"><\/i><\/a><\/span>\n<span class=\"sr-pdf\"><a rel=\"nofollow\" href=\"https:\/\/www.printfriendly.com\/print?url=\" target=\"_blank\"  title=\"Convert to PDF\"  style=\"color: #ffffff\" ><i class=\"fa fa-file-pdf\"><\/i><\/a><\/span><\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>CSS&#8217;s clip property can be used to change the size of an image, but in a different way than using the width and height properties would. The width and height elements are used to adjust the size and scale of [&#8230;]<\/p>\n<p><a class=\"more-link article\" href=\"https:\/\/cssdeck.com\/blog\/how-to-use-csss-clip-property\/\" title=\"Click to read 'How to Use CSS&#8217;s Clip Property'\">Read Article<\/a><\/p>\n","protected":false},"author":18,"featured_media":2503,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4,6,42],"tags":[],"_links":{"self":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/2502"}],"collection":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/comments?post=2502"}],"version-history":[{"count":1,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/2502\/revisions"}],"predecessor-version":[{"id":2504,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/2502\/revisions\/2504"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media\/2503"}],"wp:attachment":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media?parent=2502"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/categories?post=2502"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/tags?post=2502"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}