CSS background images
You've already seen examples of using CSS for background images all the way back in Chapter 1, Introducing Scalable Vector Graphics. This section will add some more details to using SVG in this way.
In this initial, basic example, we add an SVG image of a stylized letter R
as the background image of a div
. One important aspect is setting the background-size
property. The natural size of the SVG image is 458
by 392
. In this case it's set to be half that size in order to fit into the size of the div
:
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Mastering SVG- CSS Background Images</title> <style type="text/css"> .logo{ width: 229px; height: 196px; background: url(icon.svg); background-repeat: no-repeat; background-size: 229px 196px; } </style> </head> <body> ...