How do I use css background image property?



  • HTML Used.

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

    CSS code used.

    ...
     div {
               width: 500px;
               height: 500px;
               border: 5px solid blueviolet;
               margin: 100px auto;
    }
    ...
    

    The result is:
    10ad4444-f4ce-4e8f-840a-e6b6a29b15b7-image.png

    Let's add a background image to our div element. The background property background-image takes a URL value.

    CSS code updated.

    ...
     div {
               width: 500px;
               height: 500px;
               border: 5px solid blueviolet;
               margin: 100px auto;
               color: #fff;
               background-image: url(images/rose.jpeg);
    }
    ...
    

    The result is:
    62249d72-a28f-43a2-a20d-31763d2a4621-image.png

    To make the heading stand out we change the text color to white.


Log in to reply
 

© Lightnetics 2024