Feedback

13 Feb 2013

How to Create Pure CSS 3D Ribbon

pure CSS 3D ribbon
Since I always insists using CSS3 instead of images, here is a good example of CSS usage to create a 3D ribbon. Remember this is pure CSS, there is no image used in this to achieve it. I thank James Koster for making this happen and I hope to see even more CSS tuts from him. So lets have a look at his CSS 3D ribbon and how to create it.

James has used a single level element containing a child element with the class.
<p class="ribbon">
    <strong class="ribbon-content">Everybody loves ribbons</strong>
</p>
In order to achieve it using CSS, he has used before and after pseudo codes and good use of border properties
.ribbon {
  font-size: 16px !important;
  /* This ribbon is based on a 16px font side and a 24px vertical rhythm. I've used em's to position each element for scalability. If you want to use a different font size you may have to play with the position of the ribbon elements */

  position: relative;
  background: #ba89b6;
  color: #fff;
  text-align: center;
  padding: 1em 2em; /* Adjust to suit */
  margin: 0 0 3em; /* Based on 24px vertical rhythm. 48px bottom margin - normally 24 but the ribbon 'graphics' take up 24px themselves so we double it. */
}
.ribbon:before, .ribbon:after {
  content: "";
  position: absolute;
  display: block;
  bottom: -1em;
  border: 1.5em solid #986794;
  z-index: -1;
}
.ribbon:before {
  left: -2em;
  border-right-width: 1.5em;
  border-left-color: transparent;
}
.ribbon:after {
  right: -2em;
  border-left-width: 1.5em;
  border-right-color: transparent;
}
.ribbon .ribbon-content:before, .ribbon .ribbon-content:after {
  content: "";
  position: absolute;
  display: block;
  border-style: solid;
  border-color: #804f7c transparent transparent transparent;
  bottom: -1em;
}
.ribbon .ribbon-content:before {
  left: 0;
  border-width: 1em 0 0 1em;
}
.ribbon .ribbon-content:after {
  right: 0;
  border-width: 1em 1em 0 0;
}
If your using the ribbon inside another element, add this CSS
position: relative;
z-index: 1;
Original source: http://jameskoster.co.uk/blog/pure-css-3d-ribbon/
 

People

My Photo
We are also on Facebook We are on Twitter Home Page
Hello friends i am Jaskaran SH SD from Amritsar (Punjab) India. I love blogging. First I started a blog on science in 2010. Now I handle only this blog. I like to share the things which I know. I learn many things through blogging. I always try to make different that's why I learn many things. 

About Blog

Construct Internet is one of dedicated source for Internet, Computer and technology tutorials and development. It is Started in Oct 21 2012. We provide a professional tools for websites and blogging, along with a wide range of tutorials, How to fix etc. for computers and other technology development. Social news, Business and Social Science like topics are also followed in our blog.

We 'r Social

2012-2013 Construct Internet. Copying Without Permission is Strictly Prohibited.