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 the 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 new Web form
  • 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

<style>
.card-container
{
   text-align: center;
   margin-bottom: 2.5em;
   margin-top:2 em;
}
#canvas
{
   border: 1px solid #FFC125;
   background-color: #FFEBCD;
   -moz-box-shadow: 3px 3px 8px #222;
   -webkit-box-shadow: 3px 3px 8px #222;
   box-shadow: 3px 3px 8px #222;
}
.title
{
   text-align: center;
   font-family: Segoe UI Light, Arial, Helvetica;
   font-size: 2.2em;
   margin: 1em;
}
.info
{
   text-align: center;
   font-family: Segoe UI Light, Arial, Helvetica;
   font-size: 1.2em;
   margin: 0.25em;
}
a, a:visited, a:active, a:hover
{
   color: #fff;
   text-decoration: none;
}
a:hover
{
   text-decoration: underline;
}
</style>

Step 3 : In this part we need to work on some JavaScript. For 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.

  window.addEventListener('load', onloadHandler, false);

           function onloadHandler() {

             // get the canvas DOM element

              var canvas = document.getElementById('canvas'),

       ctx = canvas.getContext("2d"),

       width = canvas.width,

       height = canvas.height;

               // data structures - generate initial blobs

              var blobList = new BlobList();

              blobList.blobs = [

      new Blob(150, 160, 0, 90, "rgba(220,5,134,.9)"),

      new Blob(67, 136, 0, 34, "rgba(145,200,46,.9)"),

      new Blob(106, 74, 0, 22, "rgba(45,172,173,.9)"),

      new Blob(114, 52, 0, 10, "rgba(238,172,78,.75)"),

      new Blob(220, 82, 0, 56, "rgba(47,118,178,.9)"),

      new Blob(250, 138, 0, 43, "rgba(248,172,78,.9)"),

      new Blob(232, 232, 0, 25, "rgba(99,198,78,.9)"),

      new Blob(256, 222, 0, 10, "rgba(140,45,136,.9)"),

      new Blob(128, 244, 0, 36, "rgba(226,74,63,.9)"),

      new Blob(64, 188, 0, 10, "rgba(255,203,78,.9)")

   ];

Script for displaying the card holder information.


        ctx.save();

        ctx.font = "Bold 14pt Verdana";

        drawText(320, 080, "DEEPAK DWIJ", "rgb(80,80,80)");

        ctx.font = "12pt Arial";

        drawText(320, 120, "Software Developer", "rgb(80,80,80)");

        drawText(320, 140, "105 2nd Street", "rgb(80,80,80)");

        drawText(320, 160, "Fortis H 121 Noida", "rgb(80,80,80)");

        drawText(320, 180, "Mb no.-9123456789 ", "rgb(80,80,80)");

        drawText(320, 200, "[email protected]", "rgb(47,118,178)");

        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.

<body style="background-color: #B0B0B0"><center>

   <h1>C-SharpCorner &quot; Software Solution &quot; Group</h1></center>

   <hr />  

      <div class="card-container">

         <canvas id="canvas" width="560" height="300"></canvas>

      </div>
</
body>

Step 5 : The complete code for the Bussinesscard application.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="businesscard.aspx.cs" Inherits="Bussinesscard._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

 <title></title>

      <script src="jscript.js"></script>

      <script>
     
Whole JavaScript

      </script>

      <style>

     copy n paste  Step 2nd
      </style>

   </head>

   <body style="background-color: #B0B0B0"><center>

   <h1>C-SharpCorner &quot; Software Solution &quot; Group</h1></center>

   <hr />  

      <div class="card-container">

         <canvas id="canvas" width="560" height="300"></canvas>

      </div>

        </body>

</html>


Step 6 : Output Press F5

Note :
For the accurate output of HTML5 applications, you must have the Google Chrome browser in your PC.
When we run our script we will show electronic business cards in the browser.

business.gif

Here are the some useful resources.

Create Slider Carousel Images Using HTML5
Create Various Model Boxes Using HTML5
How to create Business Connectivity Services (BCS) using SharePoint Designer 2010
Credit Card Fraud Prevention using .NET Framework in C# or VB.NET
Information Card in WCF

Up Next
    Ebook Download
    View all
    Learn
    View all