Is there a way to give margin to a background-image in HTML/CSS?

Viewed 75

I need to add a snipped out background image to my html file. So while adding background-image, i cant really find a way to add margin. Please help. Is there a way in CSS to do this? Example:

body {
 background-image: url("paper.gif");
 background-color: #cccccc;
}
1 Answers

Use the background-position attribute.

body{
  background:url(https://www.gravatar.com/avatar/0fdacb141bca7fa57c392b5f03872176?s=48&d=identicon&r=PG&f=1);
  background-color:#cccccc;
  background-repeat:no-repeat;
  background-position:10px 10px;
}

background-position:10px 10px;
                    ^1st ^2nd

The first value is equal to margin-left, while the second value is equal to margin-top.

Related