Creating Shapes Using CSS3

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

In this tutorial, I am going to teach you how to make shapes like pentagon, stars, circles and etc using CSS3. Just download the source and follow the directions below.

DIRECTIONS

DON'T FORGET TO INCLUDE THIS LINK INSIDE THE HEAD TAG

<link rel="stylesheet" type="text/css" href="style.css">

CSS CODE (Save it as style.css)

Code for Pentagon

  1.  
  2. .pentagon {
  3. margin: 30px 0 0 0; /* cosmetic */
  4. position: relative;
  5. width: 54px;
  6. border-width: 50px 18px 0;
  7. border-style: solid;
  8. border-color: #fc2e5a transparent;
  9. }
  10. .pentagon:before {
  11. content: "";
  12. position: absolute;
  13. height: 0;
  14. width: 0;
  15. top: -85px;
  16. left: -18px;
  17. border-width: 0 45px 35px;
  18. border-style: solid;
  19. border-color: transparent transparent #fc2e5a;
  20. }
  21. .oval {
  22. width: 200px;
  23. height: 100px;
  24. background: #fc2e5a;
  25. -moz-border-radius: 100px / 50px;
  26. -webkit-border-radius: 100px / 50px;
  27. border-radius: 100px / 50px;
  28. }

Code for Triangle

  1.  
  2. .triangle {
  3. width: 0;
  4. height: 0;
  5. border-left: 50px solid transparent;
  6. border-right: 50px solid transparent;
  7. border-bottom: 100px solid #fc2e5a;
  8. }

Code for Star

  1.  
  2. .star {
  3. margin: 50px 0;
  4. position: relative;
  5. display: block;
  6. color: #fc2e5a;
  7. width: 0px;
  8. height: 0px;
  9. border-right: 100px solid transparent;
  10. border-bottom: 70px solid #fc2e5a;
  11. border-left: 100px solid transparent;
  12. -moz-transform: rotate(35deg);
  13. -webkit-transform: rotate(35deg);
  14. -ms-transform: rotate(35deg);
  15. -o-transform: rotate(35deg);
  16. }
  17. .star:before {
  18. border-bottom: 80px solid #fc2e5a;
  19. border-left: 30px solid transparent;
  20. border-right: 30px solid transparent;
  21. position: absolute;
  22. height: 0;
  23. width: 0;
  24. top: -45px;
  25. left: -65px;
  26. display: block;
  27. content: '';
  28. -webkit-transform: rotate(-35deg);
  29. -moz-transform: rotate(-35deg);
  30. -ms-transform: rotate(-35deg);
  31. -o-transform: rotate(-35deg);
  32.  
  33. }
  34. .star:after {
  35. position: absolute;
  36. display: block;
  37. color: #fc2e5a;
  38. top: 3px;
  39. left: -105px;
  40. width: 0px;
  41. height: 0px;
  42. border-right: 100px solid transparent;
  43. border-bottom: 70px solid #fc2e5a;
  44. border-left: 100px solid transparent;
  45. -webkit-transform: rotate(-70deg);
  46. -moz-transform: rotate(-70deg);
  47. -ms-transform: rotate(-70deg);
  48. -o-transform: rotate(-70deg);
  49. content: '';
  50. }

Code for Heart

  1. .heart {
  2. position: relative;
  3. width: 100px;
  4. height: 90px;
  5. }
  6. .heart:before,
  7. .heart:after {
  8. position: absolute;
  9. content: "";
  10. left: 50px;
  11. top: 0;
  12. width: 50px;
  13. height: 80px;
  14. background: #fc2e5a;
  15. -moz-border-radius: 50px 50px 0 0;
  16. border-radius: 50px 50px 0 0;
  17. -webkit-transform: rotate(-45deg);
  18. -moz-transform: rotate(-45deg);
  19. -ms-transform: rotate(-45deg);
  20. -o-transform: rotate(-45deg);
  21. transform: rotate(-45deg);
  22. -webkit-transform-origin: 0 100%;
  23. -moz-transform-origin: 0 100%;
  24. -ms-transform-origin: 0 100%;
  25. -o-transform-origin: 0 100%;
  26. transform-origin: 0 100%;
  27. }
  28. .heart:after {
  29. left: 0;
  30. -webkit-transform: rotate(45deg);
  31. -moz-transform: rotate(45deg);
  32. -ms-transform: rotate(45deg);
  33. -o-transform: rotate(45deg);
  34. transform: rotate(45deg);
  35. -webkit-transform-origin: 100% 100%;
  36. -moz-transform-origin: 100% 100%;
  37. -ms-transform-origin: 100% 100%;
  38. -o-transform-origin: 100% 100%;
  39. transform-origin :100% 100%;
  40. }
  41.  

Code for Infinity

  1. .infinity {
  2. position: relative;
  3. width: 212px;
  4. height: 100px;
  5. }
  6.  
  7. .infinity:before,
  8. .infinity:after {
  9. content: "";
  10. position: absolute;
  11. top: 0;
  12. left: 0;
  13. width: 60px;
  14. height: 60px;
  15. border: 20px solid #fc2e5a;
  16. -moz-border-radius: 50px 50px 0 50px;
  17. border-radius: 50px 50px 0 50px;
  18. -webkit-transform: rotate(-45deg);
  19. -moz-transform: rotate(-45deg);
  20. -ms-transform: rotate(-45deg);
  21. -o-transform: rotate(-45deg);
  22. transform: rotate(-45deg);
  23. }
  24.  
  25. .infinity:after {
  26. left: auto;
  27. right: 0;
  28. -moz-border-radius: 50px 50px 50px 0;
  29. border-radius: 50px 50px 50px 0;
  30. -webkit-transform:rotate(45deg);
  31. -moz-transform:rotate(45deg);
  32. -ms-transform:rotate(45deg);
  33. -o-transform:rotate(45deg);
  34. transform:rotate(45deg);
  35. }

Code for Circle

  1. .circle {
  2. width: 100px;
  3. height: 100px;
  4. background: #fc2e5a;
  5. -moz-border-radius: 50px;
  6. -webkit-border-radius: 50px;
  7. border-radius: 50px;
  8. }
  9.  

HTML CODE

  1. <!DOCTYPE html5>
  2. <html lang="en">
  3. <head>
  4. <title>Creating Shapes Using CSS3</title>
  5. <link rel="stylesheet" type="text/css" href="style.css">
  6. </head>
  7.  
  8. <body>
  9. <table border="1" cellpadding="10" style="text-align: center;">
  10. <tr>
  11. <th width="100">Name</th>
  12. <th>Shape</th>
  13. <th width="100">Name</th>
  14. <th>Shape</th>
  15. </tr>
  16. <tr>
  17. <td>Pentagon</td>
  18. <td><div class="pentagon"></div></td>
  19. <td>Heart</td>
  20. <td><div class="heart"></div></td>
  21. </tr>
  22. <tr>
  23. <td>Oval</td>
  24. <td><div class="oval"></div></td>
  25. <td>Infinity</td>
  26. <td><div class="infinity"></div></td>
  27. </tr>
  28. <tr>
  29. <td>Triangle</td>
  30. <td><div class="triangle"></div></td>
  31. <td>Circle</td>
  32. <td><div class="circle"></div></td>
  33. </tr>
  34. <tr>
  35. <td>Star</td>
  36. <td><div class="star"></div></td>
  37. <td>Square</td>
  38. <td><div class="square"></div></td>
  39. </tr>
  40. </table>
  41. </center>
  42. </body>
  43.  
  44.  
  45. </html>

For more information and inquiries feel free to comment below or email me at [email protected]. May this simple code help you in your projects or systems.


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.