Giter Club home page Giter Club logo

state-svg-defs's Introduction

US State SVG Defs

This repo includes a few handy things:

  • A single state-svg-defs.svg file, providing easy access to all icons in one simple file.
  • SVG directory with individual SVG icons. (SVG defs approach recommended, but you could also include files from here individually).
  • Docs demonstrating svgdefs implementation.

Demo

Check out the demo here.

Usage

Step 1 - Including the svgdefs file

Include the contents of state-svg-defs.svg in your HTML file. It needs to be included at the top of your document (or at least before you reference an icon). I recommend including it directly after the opening <body> tag.

Ways to include:

Copy the entire contents of state-svg-defs.svg and paste it after your document's opening <body> tag.

or

Copy the contents into a partial and include it after your document's opening <body> tag.
PHP: <?php include('partials/state-svg-defs.php'); ?>
Rails: <%= render 'partials/state-svg-defs' %>

Step 2 - Referencing the svgdefs file

You've already done the hard part. Using the icons is super easy!

Paste this SVG xlink snippet where the icon should appear:

<svg class="icon icon-state-MO">
  <use xlink:href="#icon-state-MO"></use>
</svg>

Step 3 - Styling icons

For best results, include the following CSS in your main stylesheet:

.icon {
  stroke-width: 0;
  stroke: currentColor;
  fill: currentColor;
}

Now you can style the icons easily by setting the color on their parent element.

For example, if the icon is wrapped in a div with a class of .state ...

<div class="state">
  <svg class="icon icon-state-MO">
    <use xlink:href="#icon-state-MO"></use>
  </svg>
</div>

... you could make the icon red using the following css:

.state {
  color: red;
}

... and you could animate the color on hover like this:

.state {
  color: red;
  transition: 500ms color;
}
.state:hover {
  color: pink;
}

Easy!

Credit

The original icons were designed by ProPublica and provided as an icon font.
I simply converted them to the (more modern) svgdefs format.
Kudos to ProPublica for the original work!

state-svg-defs's People

Contributors

coryetzkorn avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.