In the screenshot attached, when i applied the background url in body section, then ofcourse in the output, the background image gets added in the WHOLE webpage bydefault , but when I tried the background image url syntax for a particular div, then it displayed the backgroundimage for only the ‘some content’ part, why not whole image?
Basically, if i want to use a image as background for a PARTICULAR DIV only, then the image gets cropped , why not whole image is shown for the particular div.? In that case, if want that the div gets size as that of the image size by default. How to apply that?
Hello @beginner7,
To answer your wondering, when you apply a background, for example, it will be applied for all the child elements of the parent element. If you apply the background to the body tag, it will be on all the page according to the size you give to your body tag. If you apply it in a div only, div will become the parent and all the child elements inside your div will be affected.
Don’t know if I explain well
Yes, i do agree that.
BUT how to use an image for background and that too for a particular div only. If i want that the div should get the dimension(height and width) as that of the background Image bydefault?
If you agree what I said, I don’t know why you ask then. You just need to apply a background to your body and a background for your div if you want your div got a different background than your page. Simple as that.
If you want your div got a background with your entire image, just put the div size with the image dimension for example. This is one way to do. Or dimension your image at the size of your div.
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.