Setting up tiled backgrounds via CSS is a great way to add visual appeal to your website and to layout components that make up your overall design. The good news is, it's super easy, and there are some additional properties that we can make use of to further control our backgrounds. Let's check it out!
First thing's first -- we need a graphic to tile! Probably the best place to do this is in Photoshop. You can use a softened graphic, so that it'll appear as a watermark, a logo, or really anything you'd like. Make sure the graphic isn't too large, and save it as a PNG, JPEG, or GIF. Now we're ready to use it in our layout.
Next, we'll load the graphic into our layout via CSS. This'll require a little bit of hand coding, but it isn't anything too tricky to pull off. First, find the CSS rule that you'd like to apply the background graphic to. This could be an ID selector that's controlling a div element, a class rule, or any other rules you might have in use. In my example, I'm going to apply a background graphic to a redefined body element.
Add in the "background-image" property, followed by a full-colon, then "url". Then in brackets, type in the path to your graphic, followed by a semi-colon. For example, here's how my code looks:
Note that my graphic, "Background.png" is located inside a folder called "images." Be sure to save your files and preview your work in your browser. Notice how the background graphic tiles by default. We could leave things as they are, or continue to customize things further using additional CSS properties.
If you'd like to control the tiling behavior, you can add in the "background-repeat" property. You can then set the value to "repeat," "repeat-x," "repeat-y," or "no-repeat." Repeat-x and repeat-y force tiling only horizontally or vertically, while no-repeat doesn't allow tiling.
Another option that we have available is the ability to control the horizontal and vertical positioning of a non-tiling background image. Try adding in the "background-position" property, followed by two pixel values. The first pixel value is the graphic's horizontal position, and the second, its vertical position.