How to Create a Ribbon using CSS

Submitted by: 
Language: 
Visitors have accessed this post 1984 times.

In this tutorial we are going to learn how to make ribbon using CSS. You may play around with the CSS codes change the positions of the ribbon elements . Here's the code:

CSS Code:

  1. .ribbon {
  2. font-size: 16px !important;
  3. width: 300px;
  4. position: relative;
  5. background: #C50F0F;
  6. color: #fff;
  7. text-align: center;
  8. padding: 1em 2em;
  9. margin: 2em auto 3em;
  10. }
  11. .ribbon:before, .ribbon:after {
  12. content: "";
  13. position: absolute;
  14. display: block;
  15. bottom: -1em;
  16. border: 1.5em solid #B41111;
  17. z-index: -1;
  18. }
  19. .ribbon:before {
  20. left: -2em;
  21. border-right-width: 1.5em;
  22. border-left-color: transparent;
  23. }
  24. .ribbon:after {
  25. right: -2em;
  26. border-left-width: 1.5em;
  27. border-right-color: transparent;
  28. }
  29. .ribbon .ribbon-content:before, .ribbon .ribbon-content:after {
  30. content: "";
  31. position: absolute;
  32. display: block;
  33. border-style: solid;
  34. border-color: #804f7c transparent transparent transparent;
  35. bottom: -1em;
  36. }
  37. .ribbon .ribbon-content:before {
  38. left: 0;
  39. border-width: 1em 0 0 1em;
  40. }
  41. .ribbon .ribbon-content:after {
  42. right: 0;
  43. border-width: 1em 1em 0 0;
  44. }
  45. .non-semantic-protector { position: relative; z-index: 1; }

HTML Code:

  1. <div class="non-semantic-protector">
  2. <h1 class="ribbon">
  3. <strong class="ribbon-content">RED RIBBON</strong>
  4. </h1>
  5. </div>


Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.