Skip to Content
Mastering SVG
book

Mastering SVG

by Rob Larsen
September 2018
Beginner to intermediate
312 pages
7h 22m
English
Packt Publishing
Content preview from Mastering SVG

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: ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Modern SVG

Modern SVG

Amelia Bellamy-Royds, Kurt Cagle
Using SVG with CSS3 and HTML5

Using SVG with CSS3 and HTML5

Amelia Bellamy-Royds, Kurt Cagle, Dudley Storey
SVG Text Layout

SVG Text Layout

Amelia Bellamy-Royds, Kurt Cagle

Publisher Resources

ISBN: 9781788626743Supplemental Content