How do I use the css background-clip property?



  • This article demonstrates the various values of the CSS background-clip property. It shows the use of content-box, border-box and padding-box values.

    Using the demo code.

    HTML.

    ...
     <div>
            <h1>Good Morning HTML</h1>
        </div>
    ...
    

    CSS.

    ...
     div {
               width: 400px;
               height: 400px;
               border: 10px double blueviolet;
               margin: 100px auto;
               color: #fff;
               background-image: url(images/rose.jpeg);
               background-clip: content-box;
               background-repeat: no-repeat;           
          }
    ...
    

    The result is; the image is clipped at the start of the content area.

    ea27d521-baf1-4ee1-8078-7921678772b7-image.png

    The result of background-clip: padding-box the image is clipped around the padding area. Inclusive of the padding.

    caa57d6a-c6a2-4393-9061-ee06d56b3d18-image.png

    The result of background-clip: border-box which is the default is the same.


Log in to reply
 

© Lightnetics 2024