1. I don't understand how to create a background
The simplest static background is to load a large image or texture, and always render it in screen co-ordinates from (0, 0) to (screen_width, screen_height) first. You can add parallax by moving this slower than the "camera". For instance, for every two pixels the player moves, the background could scroll by one pixel.
2. move an object continuously when a button is pressed (similar to Mario walking forward) without going out of scope in the world co-ordinates.
If the "scope" of the world co-ordinates is -N to M, you just need to check if mario.x (plus or minus the character's sprite size) would be less than -N or greater than M. If so, stop moving the character and set its position to -N or M respectively. Typically, N could be 0 and M could be the length of the map, but it depends on the game - in some games, the spawn point might be (0, 0), in others that might represent the middle of the map, in others it might represent one corner of the map. The principle is the same regardless.
Alternatively, once you have collision detection working, simply ensure that the level geometry at the edges prevents the player character from leaving the playable area.