Skip to content

Instantly share code, notes, and snippets.

@kawadhiya21
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kawadhiya21/e1d3d850cdd2ca46a462 to your computer and use it in GitHub Desktop.
Save kawadhiya21/e1d3d850cdd2ca46a462 to your computer and use it in GitHub Desktop.

Social Buttons using CSS3 and Icon set

Social website such as Facebook , Twitter, Google+ and scores of others play an important role in marketing and publicity. Providing a social widget simplifies the task for the users visiting the page who share/like or rate the content and help in publicizing. Now using social media icons can be helpful as they are standardized and can be customized to fit elements unlike the social widgets which do not get updated or appear too common everywhere. We will make a simple set buttons (and definitely you can improve it) which look like this:

Social Media Button Set

This requires introduction of two CSS3 features:

  1. @import : The @import CSS rule allows to import style rules from other style sheets. We use the url to import by providing a url (the source is given at the bottom)

  2. :before : This inserts the element to appear before the element from selected element-tag. It may sound confusing now but would be clear later on.

Step One, Initiation

To begin, lets initiate the basic HTML syntax.

<html>
<head>
	<title>Social Icons using CSS3 and Icons</title>
	<style type="text/css">
</head>
	<body>
	</body>
</html>

Importing Social Icons

Now we add the social icons using the @import.

<html>
<head>
	<title>Social Icons using CSS3 and Icons</title>
	<style type="text/css">
	@import url(http://weloveiconfonts.com/api/?family=brandico);
	
        /* brandico */
	[class*="brandico-"]:before {
	  font-family: 'brandico', sans-serif;
	}
	</style>
</head>
...

We have provided a url which imports some social icons and a font. [class*="brandico-"] tells that any class which has a name similar to brandico-### will have the rules applied ie font-family is 'brandico' (or sans-serif if brandico is absent)

Using the documentation on the homepage, social icons classes can be identified which can be applied to our template. Example:

  1. Twitter : class = brandico-twitter-bird
  2. Facebook : class = brandico-facebook
  3. Google+ : class = brandico-googleplus-rect

Creating Buttons

Hence using the above three, we use them in our buttons to appear as icons. The complete code:

<html>
<head>
	<title>Social Icons using CSS3 and Icons</title>
	<style type="text/css">
	@import url(http://weloveiconfonts.com/api/?family=brandico);
	/* brandico */
	[class*="brandico-"]:before {
	  font-family: 'brandico', sans-serif;
	}
	</style>
</head>
	<body>
          <button>
            Spread
            <span class="brandico brandico-twitter-bird"></span>
            the word
          </button>
          <button>
            Like
            <span class="brandico brandico-facebook"></span>
            Please
          </button>
          <button>
            Share
            <span class="brandico brandico-googleplus-rect"></span>
            and +1
          </button>
	</body>
</html>

What :before did ?

Take the example of last button, the one of Google+. It simply forced the icon to appear before the text 'and +1'.

There are various icons and icon-sets available on this website and one can choose the best which fits the UI. But definitely, using this method simplifies the use of icons. We will come back again with more tricks.

PS: The icons used here are taken from http://weloveiconfonts.com/ which also turns out to be a free cloud host for them. This blog is an inspiration from the basic example provided on the host website.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment