0

What I'm trying to say is that when I want to add an image, it does it over and over again, like this:

(I'm making a Frogger game btw using js/css/html) You might have to zoom in to see it.

Frogger Tiled

How can I make it without that? I want to do this:

Frogger Normal

Any help will be appreciated. I think the problem is in the CSS. Also, answer my other question: Is it because I didn't add padding or a margin?

Here is my code:

/* frog */
.frog {
  background-color: darkgreen;
  background-image: url(https://www.smspower.org/uploads/Sprites/Frogger-GG-Frog-Toberescued.png);
}

Also, please don't think about the background color thing. It's fine and I want it there.

2 Answers2

0

It is happening because the image is smaller than the background so to cover up the space it repeated it self.

Add background-repeat: no-repeat; to the .frog:

/* frog */
.frog {
  background-color: darkgreen;
  background-image: url(https://www.smspower.org/uploads/Sprites/Frogger-GG-Frog-Toberescued.png);
  background-repeat: no-repeat;
}

Is it because I didn't add padding or a margin?

No!




To increase the size of the image add background-size: [size];:

The size can be anything like: 50%, 80px, 2rem.

/* frog */
.frog {
  background-color: darkgreen;
  background-image: url(https://www.smspower.org/uploads/Sprites/Frogger-GG-Frog-Toberescued.png);
  background-repeat: no-repeat;
  background-size: 30px;
}
Manas Khandelwal
  • 3,790
  • 2
  • 11
  • 24
0

Because background-repeat is repeat by default. You should add to your code background-repeat: no-repeat.

/* frog */
.frog {
  background-color: transparent;
  background-image: url(https://www.smspower.org/uploads/Sprites/Frogger-GG-Frog-Toberescued.png);
  background-repeat: no-repeat;
}
AfifeBetul
  • 136
  • 6