DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Coding
  3. Languages
  4. How To Create A CSS Animated Share Button

How To Create A CSS Animated Share Button

Paul Underwood user avatar by
Paul Underwood
·
Oct. 30, 12 · Interview
Like (0)
Save
Tweet
Share
5.17K Views

Join the DZone community and get the full member experience.

Join For Free

Every website now has social network share buttons on their site, if you don't have them then you really should get one. They're a great way to give your visitors easy access to share your content with their friends and followers.

The thing with social network share buttons is that they all look the same on every website, you can take this two ways. It's either a good thing because people will recognise them and understand how to use them or it's a bad thing because now your website looks the same as every other website on the internet.

In this tutorial we are going to create a share button which uses CSS animation to display the links to share the current page on Facebook, Twitter, Google Plus and Pinterest.

First we are going to start off creating the HTML which will display some text such as Share This Page. Then when we hover over this text we want to use CSS animation to display the share buttons.

View the demo to see what we are going to create.

Demo

The HTML

The HTML we are going to use has many different sections which we are splitting up using different HTML elements all of this is going to be wrapped up in the div with a class of share_button.

<div class="share_button">
</div>

The button is going to open up in the middle to display the share buttons so we are going to add 2 sections which we will use to split the text.

<div class="share_button">
<section>
<article>
<h1>Share th</h1>
</article>
</section>
<section>
<article>
<h1>is Page</h1>
</article>
</section></div>

 

Within these 2 sections we are going to show or hide the article tags to display the share buttons. In this example there will be 2 share buttons on each article tag, totally 4 share buttons which will be displayed.

Below is the full HTML code with all of the social buttons in the different sections.

Full HTML Code

The below code is to be used on a WordPress single.php page as it uses the WordPress function the_permalink(). If you are not using this on WordPress remove this function and replace it with the URL you want to share.

<div class="share_button">
<section>
<article>
<h1>Share th</h1>
</article>
<article>
<h2><a href="http://www.facebook.com/sharer.php?u=<?php the_permalink(); ?>" title="Share On Facebook">F</a></h2>
<h2><a href="http://twitter.com/home?status=Share On Twitter <?php the_permalink(); ?>" title="Share On Twitter">T</a></h2>
</article>
</section>
<section>
<article>
<h1>is Page</h1>
</article>
<article>
<h2><a href="https://plus.google.com/share?url=<?php the_permalink(); ?>" title="Share On Google Plus">G</a></h2>
<h2><a href="http://pinterest.com/pin/create/button/?url=<?php the_permalink(); ?>" title="Share On Pinterest">P</a></h2>
</article>
</section></div>

The CSS

The CSS will be done in two stages first we will be creating the button then we will be creating the animation to change the look of the sections from displaying the text to displaying the social buttons.

Use the below CSS to create the look of the button.

.share_button { width: 300px;height: 70px; margin:0 auto; }
.share_button section { width: 50%; height: inherit; float: left; }
.share_button section h1 { margin-top: 13%; overflow: hidden; width: 100%;color: #fff;}
.share_button section article { position: absolute; height: inherit; width: 150px; background: #d4d5d9;
	-webkit-transition: all 600ms;
	-moz-transition: all 600ms;
	-o-transition: all 600ms;
	-ms-transition: all 600ms;
	transition: all 600ms;
	text-align: center;
}
.share_button section article h2 { display: inline-block; width: 40%;	height: 40px; overflow: hidden;	margin-top: 10%; cursor: pointer; }
.share_button section article h2:hover { text-shadow:2px 2px 2px #555; }
.share_button section article h2 a { color:#FFF; text-decoration: none; }
.share_button section:first-child article:first-child{ text-align: right; }
.share_button section:last-child article:first-child{ text-align: left; }

With the button created you can add a hover effect to display the social buttons in the background.

.share_button section:first-child article:last-child,
.share_button:hover section:first-child article:first-child {
	-webkit-transform: rotateY(90deg);
	-moz-transform: rotateY(90deg);
	-o-transform: rotateY(90deg);
	-ms-transform: rotateY(90deg);
	transform: rotateY(90deg);
}
.share_button section:last-child article:last-child,
.share_button:hover section:last-child article:first-child {
	-webkit-transform: rotateY(-90deg);
	-moz-transform: rotateY(-90deg);
	-o-transform: rotateY(-90deg);
	-ms-transform: rotateY(-90deg);
	transform: rotateY(-90deg);
}
.share_button:hover section:first-child article:last-child,
.share_button:hover section:last-child article:last-child {
	-webkit-transform: rotateY(0deg);
	-moz-transform: rotateY(0deg);
	-o-transform: rotateY(0deg);
	-ms-transform: rotateY(0deg);
	transform: rotateY(0deg);
}

View the demo to see what has been created with the above code.

Demo

 

 

 

CSS

Published at DZone with permission of Paul Underwood, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • SAST: How Code Analysis Tools Look for Security Flaws
  • How To Generate Code Coverage Report Using JaCoCo-Maven Plugin
  • How and Why You Should Start Automating DevOps
  • Core Machine Learning Metrics

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: