How do I make my image start after css padding?



  • This article demonstrates the various values of the CSS background-origin element. It shows the use of content-box and border-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-origin: content-box;
               background-repeat: no-repeat;           
          }
    ...
    

    Using the background-origin: content-box CSS property, the result is the image appears after the padding.

    24dee0c5-8e49-47e7-ac48-9980f837527e-image.png

    Using the background-origin: border-box CSS property, the result is the image appears from the border.

    a42e30f2-49e8-41c3-83af-5f4f705d0b14-image.png

    The default is start the image inclusive of the padding. Which is the CSS value background-origin: padding-box To demonstrate this we used a double border.

    db3ace7c-b394-41cb-91d5-27ec55692d5c-image.png


Log in to reply
 

© Lightnetics 2024