{"id":341,"date":"2022-05-23T20:22:35","date_gmt":"2022-05-23T20:22:35","guid":{"rendered":"https:\/\/gyanipandit.com\/programming\/?p=341"},"modified":"2022-05-23T20:22:36","modified_gmt":"2022-05-23T20:22:36","slug":"css-background-clip-property","status":"publish","type":"post","link":"https:\/\/gyanipandit.com\/programming\/css-background-clip-property\/","title":{"rendered":"CSS Background Clip Property"},"content":{"rendered":"<p style=\"text-align: center;\"><strong>CSS Background Clip<\/strong><\/p>\n<p>With this property, we are determining whether the background of an element extends underneath its border-box, padding-box, or content-box. Let&#8217;s now try playing with this property.<\/p>\n<p>The values that we have got for the property are border-box (which is the default), padding-box (which means that the background of the element extends underneath the padding box), content-box(which means that the background of the element) extends underneath the content-box, and there is another value as text, where the background appears to be clipped to the foreground text.<\/p>\n<p>If you are confused between what is border-box, padding-box, etc, just remember the box model thing.<\/p>\n<p>There, we have some content, and the padding is the space around the content, inside the border, and then comes the border, and then outside the border, there comes the margin thing.<\/p>\n<p>So, when we are declaring nothing about the background-clip property, it has the default value, which is the border-box. Now, have a look at the below example, to get an idea of this property &#8211;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-342 size-full\" src=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/04\/The-background-clip-property.jpg\" alt=\"The background-clip property\" width=\"830\" height=\"312\" srcset=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/04\/The-background-clip-property.jpg 830w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/04\/The-background-clip-property-300x113.jpg 300w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/04\/The-background-clip-property-768x289.jpg 768w\" sizes=\"auto, (max-width: 830px) 100vw, 830px\" \/><br \/>\nIf we have a look at the output, it appears to be something like this &#8211;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-343 size-full\" src=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/04\/The-background-clip-property-1.jpg\" alt=\"The background-clip property 1\" width=\"1023\" height=\"196\" srcset=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/04\/The-background-clip-property-1.jpg 1023w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/04\/The-background-clip-property-1-300x57.jpg 300w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/04\/The-background-clip-property-1-768x147.jpg 768w\" sizes=\"auto, (max-width: 1023px) 100vw, 1023px\" \/><\/p>\n<p>As you can see, when we are not specifying anything, the value for the background-clip property is border-box. So, you can see that the background extends underneath the border as well.<\/p>\n<p>Now, if we set the background-clip property to padding-box instead, then you will observe that the background of the element extends underneath the padding-box, and it is not underneath the border now. Have a look at the below example, where we have made just one change.<\/p>\n<p>Remember that we had earlier set some padding for the element, so as to clearly visualize everything.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-344 size-full\" src=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/04\/The-background-clip-property-2.jpg\" alt=\"\" width=\"839\" height=\"306\" srcset=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/04\/The-background-clip-property-2.jpg 839w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/04\/The-background-clip-property-2-300x109.jpg 300w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/04\/The-background-clip-property-2-768x280.jpg 768w\" sizes=\"auto, (max-width: 839px) 100vw, 839px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-345 size-full\" src=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/04\/The-background-clip-property-3.jpg\" alt=\"\" width=\"1023\" height=\"168\" srcset=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/04\/The-background-clip-property-3.jpg 1023w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/04\/The-background-clip-property-3-300x49.jpg 300w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/04\/The-background-clip-property-3-768x126.jpg 768w\" sizes=\"auto, (max-width: 1023px) 100vw, 1023px\" \/><\/p>\n<p>As you can see in the output, the background of the element is only extended underneath the padding box. Now, if we try putting another value, which is content-box, then have a look at what this thing looks like. Have a look at the below example &#8211;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-346 size-full\" src=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/04\/The-background-clip-property-4.jpg\" alt=\"\" width=\"836\" height=\"309\" srcset=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/04\/The-background-clip-property-4.jpg 836w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/04\/The-background-clip-property-4-300x111.jpg 300w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/04\/The-background-clip-property-4-768x284.jpg 768w\" sizes=\"auto, (max-width: 836px) 100vw, 836px\" \/><\/p>\n<p>Have a look at the output \u2192<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-347 size-full\" src=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/04\/The-background-clip-property-5.jpg\" alt=\"\" width=\"1022\" height=\"170\" srcset=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/04\/The-background-clip-property-5.jpg 1022w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/04\/The-background-clip-property-5-300x50.jpg 300w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/04\/The-background-clip-property-5-768x128.jpg 768w\" sizes=\"auto, (max-width: 1022px) 100vw, 1022px\" \/><\/p>\n<p>As you can see, the background is now extended underneath the content box. Now, we are going to see the next value, which is text. When we set the property value to text, the background of the element is clipped to the foreground text. Let&#8217;s now have a look at what happens when you do it.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-348 size-full aligncenter\" src=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/04\/The-background-clip-property-6.jpg\" alt=\"\" width=\"824\" height=\"346\" srcset=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/04\/The-background-clip-property-6.jpg 824w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/04\/The-background-clip-property-6-300x126.jpg 300w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/04\/The-background-clip-property-6-768x322.jpg 768w\" sizes=\"auto, (max-width: 824px) 100vw, 824px\" \/><\/p>\n<p>If you carefully observe the properties that we have applied, you can see that we have a background image, and some padding, and we are using the background-clip property, also one with a WebKit vendor prefix.<\/p>\n<p>We also have specified the color property with a value of transparency. If the WebKit thing is missing from your code, and you are viewing the file in chrome, you would see some output that is not usual. If you are using Mozilla Firefox, you can see the output as we have.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-349 size-full\" src=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/04\/The-background-clip-property-7.jpg\" alt=\"\" width=\"1023\" height=\"151\" srcset=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/04\/The-background-clip-property-7.jpg 1023w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/04\/The-background-clip-property-7-300x44.jpg 300w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/04\/The-background-clip-property-7-768x113.jpg 768w\" sizes=\"auto, (max-width: 1023px) 100vw, 1023px\" \/><\/p>\n<p>As you can see, the background of the element appears to be painted to the foreground text. So, this way, you can make use of the background-clip property.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>CSS Background Clip With this property, we are determining whether the background of an element extends underneath its border-box, padding-box, or content-box. Let&#8217;s now try playing with this property. The values that we have got for the property are border-box (which is the default), padding-box (which means that the background of the element extends underneath [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":{"0":"post-341","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-css-tutorial"},"_links":{"self":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/341","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/comments?post=341"}],"version-history":[{"count":2,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/341\/revisions"}],"predecessor-version":[{"id":1416,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/341\/revisions\/1416"}],"wp:attachment":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/media?parent=341"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/categories?post=341"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/tags?post=341"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}