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
Partner Zones AWS Cloud
by AWS Developer Relations
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
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Github Ribbons in CSS

Github Ribbons in CSS

Terrence Ryan user avatar by
Terrence Ryan
·
Jan. 27, 12 · Interview
Like (1)
Save
Tweet
Share
7.62K Views

Join the DZone community and get the full member experience.

Join For Free

Github has these cool ribbon images that you can use if you want to encourage forking your project on your site. They're great and I wanted to use them on a little project I am working on. However, one of my goals was not to use any images, but rather produce all display elements with CSS.

It was a little bit of trial and error but I got it working. Basically you do the following:

  • Create a link in a div with an id of "banner"
  • Force div#banner to be 149px x 149px.
  • Set overflow to "hidden"

This creates a square display area that won't show things that stretch out past the bounds of the box.

  • Create an A link
  • Tilt it using a CSS transform
  • Use relative positioning to pull the ribbon into place
  • Use CSS shadows to tweak the text and ribbon shadows
  • Finally I use a CSS gradient in the background of the ribbon to give it the bands that run along the edge.
<!DOCTYPE html> 
<html> 
	<head> 
	<title>Banner Example</title> 
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<style>
		body{ 
			padding: 0;
			margin: 0;
		}
	
		#banner{
			height: 149px;
			width: 149px;
			overflow:hidden;
			padding: 0;
			margin: 0;
		}
		
		#banner a{
			
			display: block;
			width: 190px;
			font-size: 14px;
			font-family: Frutiger, "Frutiger Linotype", Univers, Calibri, "Gill Sans", "Gill Sans MT", 
				"Myriad Pro", Myriad, "DejaVu Sans Condensed", "Liberation Sans", "Nimbus Sans L", Tahoma, 
				Geneva, "Helvetica Neue", Helvetica, Arial, sans serif;
			background-color: #333;
			color: #FFF;
			word-spacing: 2px;
			text-decoration: none;
			padding: 5px 15px 5px 25px;
			
			position:relative;
			left: 20px;
			top: -37px;
			text-align: center;
			
			-moz-transform-origin: 0 0 ;
			-moz-transform:rotate(45deg);
			-moz-box-shadow:    1px 1px 5px 1px #666;
			
			-webkit-transform-origin: 0 0 ;	
			-webkit-transform:rotate(45deg);
			-webkit-box-shadow: 1px 1px 5px 1px #666;
			
			-ms-transform-origin: 0 0 ;	
			-ms-transform:rotate(45deg);
			-ms-box-shadow: 1px 1px 5px 1px #666;
			
			transform-origin: 0 0 ;	
			transform:rotate(45deg);
			box-shadow: 1px 1px 5px 1px #666;
			
			background-image: linear-gradient(bottom, #000000 3%, #666666 5%, #000000 7%, #000000 93%, #666666 95%, #000000 97%);
			background-image: -o-linear-gradient(bottom, #000000 3%, #666666 5%, #000000 7%, #000000 93%, #666666 95%, #000000 97%);
			background-image: -moz-linear-gradient(bottom, #000000 3%, #666666 5%, #000000 7%, #000000 93%, #666666 95%, #000000 97%);
			background-image: -webkit-linear-gradient(bottom, #000000 3%, #666666 5%, #000000 7%, #000000 93%, #666666 95%, #000000 97%);
			background-image: -ms-linear-gradient(bottom, #000000 3%, #666666 5%, #000000 7%, #000000 93%, #666666 95%, #000000 97%);
			
			background-image: -webkit-gradient(
				linear,
				left bottom,
				left top,
				color-stop(0.03, #000000),
				color-stop(0.05, #666666),
				color-stop(0.07, #000000),
				color-stop(0.93, #000000),
				color-stop(0.95, #666666),
				color-stop(0.97, #000000)
			);	
			
		}
	
	</style>
</head> 
<body> 
	<div id="banner"><a href="">Fork me on GitHub</a></div>
	<a href="http://github.com/you"><img style="position: absolute; top: 0; left: 149px; border: 0;" src="https://a248.e.akamai.net/assets.github.com/img/7afbc8b248c68eb468279e8c17986ad46549fb71/687474703a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub"></a>
</body>
</html>

Issues:

  • It's not a pixel perfect representation.
  • It doesn' work on IE before 9. It doesn't appear at all.

I'm not sure if I'm going to use this. I'll sound judgmental here, but the fact that it doesn't show up on IE less than 9 seems like a good thing. Do I want a developer on my project that isn't using the latest browser? Probably not.

Demo
See the live demo here.

Update

A couple people pointed out that there was a weird doubling of the letters on their browser (Chrome on Windows, and Safari on iPad.) Looks like it was caused by a slight text-shadow I had on the text. The text on the original banner has some anti-aliasing going on, and on some browsers, the text shadow helps it look a little smoother, but on others you get that doubling. So I've removed the text shadow.  Display should be a little more consistent.

 

Source: http://www.terrenceryan.com/blog/post.cfm/github-ribbons-in-css

CSS GitHub

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Introduction to Container Orchestration
  • What Are the Benefits of Java Module With Example
  • Tracking Software Architecture Decisions
  • Building Microservice in Golang

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: