SVGとは

Scalable Vector Graphicsは、XMLベースの、2次元ベクターイメージ用の画像形式の1つである。
参照元:wikipediaから

SVGデータをCSS化する

目的:Sketch appやillustrator CCなどで作成されたSVGデータをCSSで表示。
scene:アイコンなどのマークアップ時。

SVGデータをBase64コードにencode

XMLデータからBase64コードに変換し、backgroundプロパティに指定。

下記のサイトなど使うと、background-imageプロパティ付きで変換してくれる。

デザインに合わせてプロパティで調整

下記は、本サイトのタグ部分のアイコン「 」で使用した一例です。

.c-icon-tags::before {
	content: ' ';
	/* 色々 */
	background-image: url("data:image/svg+xml;charset=utf8,%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22UTF-8%22%3F%3E%3Csvg%20width%3D%22179px%22%20height%3D%22188px%22%20viewBox%3D%220%200%20179%20188%22%20version%3D%221.1%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20%3E%20%3Ctitle%3Eicon_tag%3C%2Ftitle%3E%20%3Cdesc%3ECreated%20with%20Sketch.%3C%2Fdesc%3E%20%3Cdefs%3E%3C%2Fdefs%3E%20%3Cg%20id%3D%22Desktop-HD%22%20stroke%3D%22none%22%20stroke-width%3D%221%22%20fill%3D%22none%22%20fill-rule%3D%22evenodd%22%20transform%3D%22translate(-152.000000%2C%20-130.000000)%22%3E%20%3Cg%20id%3D%22icon_tag%22%20transform%3D%22translate(154.000000%2C%20133.000000)%22%20fill%3D%22%234A4A4A%22%20stroke%3D%22%23FFFFFF%22%3E%20%3Cpath%20d%3D%22M161.524126%2C28.5773799%20C163.335905%2C28.7915314%20164.77322%2C30.2044688%20165.018331%2C32.0123192%20L173%2C90.8823529%20L75.5825243%2C183%20L0%2C111.529412%20L97.4174757%2C21%20L161.524126%2C28.5773799%20Z%20M130.76699%2C68.4705882%20C140.043229%2C68.4705882%20147.563107%2C61.3598166%20147.563107%2C52.5882353%20C147.563107%2C43.816654%20140.043229%2C36.7058824%20130.76699%2C36.7058824%20C121.490751%2C36.7058824%20113.970874%2C43.816654%20113.970874%2C52.5882353%20C113.970874%2C61.3598166%20121.490751%2C68.4705882%20130.76699%2C68.4705882%20Z%22%20id%3D%22Combined-Shape%22%20stroke-width%3D%222%22%3E%3C%2Fpath%3E%20%3Cpath%20d%3D%22M162.524126%2C7.57737991%20C164.335905%2C7.79153139%20165.77322%2C9.20446879%20166.018331%2C11.0123192%20L174%2C69.8823529%20L76.5825243%2C162%20L1%2C90.5294118%20L98.4174757%2C0%20L162.524126%2C7.57737991%20Z%20M133.76699%2C51.4705882%20C143.043229%2C51.4705882%20150.563107%2C44.3598166%20150.563107%2C35.5882353%20C150.563107%2C26.816654%20143.043229%2C19.7058824%20133.76699%2C19.7058824%20C124.490751%2C19.7058824%20116.970874%2C26.816654%20116.970874%2C35.5882353%20C116.970874%2C44.3598166%20124.490751%2C51.4705882%20133.76699%2C51.4705882%20Z%22%20id%3D%22Combined-Shape-Copy%22%20stroke-width%3D%224%22%3E%3C%2Fpath%3E%20%3C%2Fg%3E%20%3C%2Fg%3E%3C%2Fsvg%3E");
}

Tags