Creating a Business Card Using HTML 5

Introduction

 
This article is about something very important and interesting; that is creating a business card using HTML5. In this section, we will use the canvas tag. When we run our script we will show electronic business cards in the browser.
 
Here we will use some JavaScript and some styles along with HTML code. Just go through the steps to see how to create this application.
 
Let's see how the Bussinesscard application can be created. To do so use the following steps.
 
Step 1 : Open a HTML editor or Visual Studio.
sd.gif
 
Open File menu ->select new ->Choose Website then.
 
0000.jpg
 
This is where we will create an HTML5 application.
  • Go to Solution Explorer
  • Right-click on the Application name
  • Select Add-->add new item
  • Now in the window that opens, select an HTML page or a new Webform
  • Rename it to businesscard.aspx
busniss.gif
 
Step 2: In this section, we will create the style for the media and create the .css on the media screen. Put the given script in the Head section of the HTML or between the <head>--</head> tags. Here the CSS is used for design purposes.
 
CSS Script
  1. <style>  
  2. .card-container  
  3. {  
  4.    text-aligncenter;  
  5.    margin-bottom2.5em;  
  6.    margin-top:2 em;  
  7. }  
  8. #canvas  
  9. {  
  10.    border1px solid #FFC125;  
  11.    background-color#FFEBCD;  
  12.    -moz-box-shadow: 3px 3px 8px #222;  
  13.    -webkit-box-shadow: 3px 3px 8px #222;  
  14.    box-shadow: 3px 3px 8px #222;  
  15. }  
  16. .title  
  17. {  
  18.    text-aligncenter;  
  19.    font-family: Segoe UI Light, ArialHelvetica;  
  20.    font-size2.2em;  
  21.    margin1em;  
  22. }  
  23. .info  
  24. {  
  25.    text-aligncenter;  
  26.    font-family: Segoe UI Light, ArialHelvetica;  
  27.    font-size1.2em;  
  28.    margin0.25em;  
  29. }  
  30. a, a:visited, a:active, a:hover  
  31. {  
  32.    color#fff;  
  33.    text-decorationnone;  
  34. }  
  35. a:hover  
  36. {  
  37.    text-decorationunderline;  
  38. }  
  39. </style> 
Step 3: In this part, we need to work on some JavaScript. To fully understanding how the JavaScript works, download the attached .rar file and run the Bussinesscard application.
 
JavaScript for the Canvas alignment and setting the Hexa colors.  
  1. window.addEventListener('load', onloadHandler, false);  
  2.            function onloadHandler() {  
  3.              // get the canvas DOM element  
  4.               var canvas = document.getElementById('canvas'),  
  5.        ctx = canvas.getContext("2d"),  
  6.        width = canvas.width,  
  7.        height = canvas.height;  
  8.                // data structures - generate initial blobs  
  9.               var blobList = new BlobList();  
  10.               blobList.blobs = [  
  11.       new Blob(150, 160, 0, 90, "rgba(220,5,134,.9)"),  
  12.       new Blob(67, 136, 0, 34, "rgba(145,200,46,.9)"),  
  13.       new Blob(106, 74, 0, 22, "rgba(45,172,173,.9)"),  
  14.       new Blob(114, 52, 0, 10, "rgba(238,172,78,.75)"),  
  15.       new Blob(220, 82, 0, 56, "rgba(47,118,178,.9)"),  
  16.       new Blob(250, 138, 0, 43, "rgba(248,172,78,.9)"),  
  17.       new Blob(232, 232, 0, 25, "rgba(99,198,78,.9)"),  
  18.       new Blob(256, 222, 0, 10, "rgba(140,45,136,.9)"),  
  19.       new Blob(128, 244, 0, 36, "rgba(226,74,63,.9)"),  
  20.       new Blob(64, 188, 0, 10, "rgba(255,203,78,.9)")  
  21.    ];  
Script for displaying the cardholder information.        
  1. ctx.save();  
  2. ctx.font = "Bold 14pt Verdana";  
  3. drawText(320, 080, "DEEPAK DWIJ""#505050");  
  4. ctx.font = "12pt Arial";  
  5. drawText(320, 120, "Software Developer""#505050");  
  6. drawText(320, 140, "105 2nd Street""#505050");  
  7. drawText(320, 160, "Fortis H 121 Noida""#505050");  
  8. drawText(320, 180, "Mb no.-9123456789 ""#505050");  
  9. drawText(320, 200, "[email protected]""#2f76b2");  
  10. ctx.restore();  
Step 4 : In this section we are going to become familiar with the body part of HTML scripting. Replace this script from the body section of the businesscard.aspx page.
  1. <body style="background-color: #B0B0B0"><center>  
  2.    <h1>C-SharpCorner " Software Solution " Group</h1></center>  
  3.    <hr />    
  4.       <div class="card-container">  
  5.          <canvas id="canvas" width="560" height="300"></canvas>  
  6.       </div> </body>   
Step 5 : The complete code for the Bussinesscard application.
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="businesscard.aspx.cs" Inherits="Bussinesscard._Default" %>  
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  3. <html xmlns="http://www.w3.org/1999/xhtml">  
  4. <head runat="server">  
  5.  <title></title>  
  6.       <script src="jscript.js"></script>  
  7.       <script>      Whole JavaScript  
  8.       </script>  
  9.       <style>  
  10.      copy n paste  Step 2nd       </style>  
  11.    </head>  
  12.    <body style="background-color: #B0B0B0"><center>  
  13.    <h1>C-SharpCorner " Software Solution " Group</h1></center>  
  14.    <hr />    
  15.       <div class="card-container">  
  16.          <canvas id="canvas" width="560" height="300"></canvas>  
  17.       </div>  
  18.         </body>  
  19. </html> 
Step 6: Output Press F5
 
Note: For the accurate output of HTML5 applications, you must have the Google Chrome browser on your PC. When we run our script we will show electronic business cards in the browser.
 
business.gif
 
Here are some useful resources.