Saturday, February 28, 2015

Adding CSS into an HTML page to customize a div



From the previous posts, you have learned to create a simple webpage. But our goal is to crate a full functional webpage. That's why we need to know to use the <div> tag. Like all other tags, every opening <div> tag will be ended with a closing </div> tag.

A <div> tag is nothing so special till using CSS (Cascading Style Sheets) for it. So we have to use CSS also. However let's follow the steps below to add a CSS Style Sheet with our existing webpage and to format <div> differently.

 Step 01  Remind the basic codes we have used before
Let's remember the codes again we have used to create a simple webpage before. But, there is nothing inside the <body> and </body> tags here.

N.B. Only the texts and/or contents inside the <body> and </body> tags will be displayed on a web browser.
<!DOCTYPE html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <title>iDhali</title>
 </head>
 
 <body>
  
   
 </body>
</html>
 Step 02  Now add a <div> tag inside the <body> and </body> tags
Now we will add a <div> tag inside the <body> and </body> tags. But the opening <body> tag will be with an attribute class=" " and the value of the class may be anything you like. For example: the code will be like...
<!DOCTYPE html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <title>iDhali</title>
 </head>

 <body>
  <div class="container">
   
  </div>   
 </body>
</html>
Still now the above code will display nothing on the webpage. But if you keep any text inside the <div> and </div> tags, then the texts will be displayed as usual.

 Step 03  Let's add some CSS in the page
Now we will add some CSS codes to style the <div> according to our wish. Look, I have added a class with the value container to target the <div> by CSS. Let's look the codes given below.
<!DOCTYPE html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <title>iDhali</title>
  <style type="text/css">
   .container{
    width: 600px;
    height: 300px;
    background-color: silver;
   }
  </style>
 </head>

 <body>
  <div class="container">
   
  </div>   
 </body>
</html>

You have already noticed that I have added 7 new lines before the closing </head> tag. These are the CSS codes that will make the <div> visible in silver color and 600 X 300px in size.

After opening the HTML document in a web browser you will get an silver colored box of 600px by 300px.

Things that you should know
01. The CSS code will go inside the <head> and </head> tags.
02. CSS codes basically goes in another file named style.css, then we have to link that .css file using a line like <link rel="stylesheet" type="text/css" href="css/style.css"> and this line will also go inside the <head> and </head> tags.
03. But when we will keep the CSS codes into the HTML page, then the CSS codes will go inside the tags <style> and </style>

Description about the newly added 7 lines are given below
<style type="text/css"> is the sixth line of the above HTML document, that is used to wrap all the CSS codes. Besides </style> is the closing tag for the 6th line. All the CSS codes must be inside <style type="text/css"> and </style> tags.

.container is the 7th line of the HTML document, that is used to target the DIV with class container. Just after .container there is an opening curly brace { and at the 11th line there is also a closing curly brace }. All the customization for the div will be inside these two curly braces.

N.B. Not only using class like <div class="container">, but also we may use id like <div id="container"> to target a <div>. But then we have to use #container instead of .container to customize.

The lines 8, 9 and 10 are very simple and descriptive. The 8th line says that the width of the div will be 600px, the 9th line says that the height of the div will be 300px and finally the 10th line says that the background color of the div will be silver.

N.B. I have used silver color, you may use another color like red, green, blue etc. And most importantly you can use color code instead of the color name. For example: #d0d0d0 is the color code for silver color. Let's know the basic color codes.


More customization of a div will be described in the next post. Stay tuned to read the next post. Must leave a comment if it is helpful for you.

« Previous Tutorial
Next Tutorial »


Advertisement

Tuesday, February 24, 2015

Detail about the heading tags


Heading Tags

h1, h2, h3, h4, h5 and h6 are six heading tags.  <h1> defines the most important heading, where <h6> defines the least important heading. Examples are given below...

Example of Heading 1

Example of Heading 2

Example of Heading 3

Example of Heading 4

Example of Heading 5
Example of Heading 6


Though different heading tags represent the texts in different sizes, but you shouldn't use heading tags for text's size issue. The heading tags should be used depending on the importance of the text. For example the title of a post/article should go inside the <h1> and </h1>tags. Similarly, the sub-heading basically the second most important title of an article should go inside the <h2> and </h2> tags.

When you will keep some text inside the <h1> and </h1> tags, then the search engine will recognize the text as the most important text. So, heading tags are used for SEO purpose. But all the text should not go inside the header tags.

Only the important texts like keywords may go inside the heading tags.


<u> tag for underlined text

In html <u> tag is used to make the texts underlined. If you keep any text inside the <u> and </u> tags then the texts will be underlined when it will be displayed in a web browser.


<i> tag for italic text

Texts inside the <i> and </i> tags will be displayed as italic text in the web browsers.



<b> tag for bold text

Texts inside the <b> and </b> tags will be displayed as bold text.


<p> tag for paragraph

Texts to represent as paragraph will go inside the <p> and </p> tags.



<br /> tag for line break

Besides, the <br/> tag is used to break a line. Content (may be texts, images etc.) after the <br /> tag will be displayed in the next line.

» Learn more text formatting

« Previous Tutorial
Next Tutorial »




Monday, February 23, 2015

Let's learn about the codes you've used to create a webpage

From the previous post you have learned to create a webpage using the codes given below. In this post you will learn detail about the codes/tag.
<!DOCTYPE html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <title>iDhali</title>
 </head>
 <body>
  <h1>This is a Header</h1>
  <p>This is a Paragraph</p>
  <b>This is Bold Text</b>
  <i>This is Italic Text</i>
  <u>This is Underlined Text</u>
 </body>
</html>

<!DOCTYPE html>
The first line <!DOCTYPE html> is the doctype declaration. This line must be the very first line of an HTML document. This line will be before the opening tag <html> but <!DOCTYPE> itself is not an HTML tag. Basically <!DOCTYPE> declaration in an instruction for the web browsers that tells the browser in what version of HTML is used. The line <!DOCTYPE html> is used to define that the page is written in HTML 5.

<html>
The second line is <html lang="en">, that is an opening tag. That's why an closing tag </html> is used at the line number 14. Inside the opening <html> tag lang is an attribute what's value is en. lang="en" is used to tells the browser that the language of the html document will be English. You can use <html lang="bn"> for Bangla. <html> element is a container to hold all other HTML elements inside it.

N.B. For every opening tag a closing tag is must. Sometimes we will use some self closed tags like <br/>, <hr/> etc.

<head>
In the third line there is an <head> tag and another closing </head> tag is given at the line number 6. The <head> element is a container for all the head elements like <title>, <link>, <style>, <script>, <noscript>, <base> etc. When you will link an .css file (stylesheet), then the tag <link> will be used inside the <head> and </head> tags. Meta information, keywords, JavaScript etc. will also go inside the <head> and </head> tags.

<meta charset="UTF-8">
The fourth line is <meta charset="UTF-8"> where <meta> is an tag that provides metadata about the HTML document. Metadata will not be displayed on a page, but it is used to specify page description, keywords etc. charset is the short of Character Set that specify the character encoding for the HTML document.

<title>
The fifth line is <title>iDhali</title>. Inside the <title> and </title> tags what will keep will be displayed as the website title. For example iDhali is showing as the title of this page you are reading now.

<body>
In the 7th line there is an opening <body> tag and in the 13th line there is also a closing </body> tag. This is the main container of a webpage. The data and/or information given inside the <body> and </body> tags will be displayed on the webpage.

There are some HTML tags like <h1>, <p>, <b>, <i>, <u> and also CSS codes to format and/or beautify the content you want to show on the page. The tags used inside the <body> and </body> tags are described in the next tutorial briefly.

« Previous Tutorial
Next Tutorial »


Thursday, February 19, 2015

Shortcuts you need as a coder/programmer

During Using Notepad++
01. Ctrl+D to copy the current line
02. Ctrl+L to delete the current line
03. F11 to toggle full screen mode
04. Ctrl+B to go to the matching brach

During Using SublimeText
01. Ctrl+Shift+P to open package control

During Using TextPad
01. Ctrl+1 to   compile the program
02. Ctrl+2 to run the program


N.B. You please share the shortcuts you know. I will update this post again after having any new shortcut.

+MD MONIRUL ALOM is specially requested to share his known shortcuts.

Sunday, February 15, 2015

C program to perform a user defined mathematical operation

The c program given below is able to perform a mathematical operation according to users interest. After running the program you will be asked to provide a number, that will be stored into a float type variable number1.

Soon, you will be asked to provide another number, that will be stored into a float type variable number2.

Later a message will be displayed to choose an operation you want to perform. For example: if you want to add those two numbers, then you have to provide the sign +. Similarly - for subtraction, * for multiplication and / for division.

Actually the sign you will provide, that will be stored as a character into the variable choice. Later, the if-else condition will one of those four operations depending on the value stored into the variable choice. But if there is anything else except +, -, * or / then a message will be displayed saying Invalid Operation!!!

//user defined mathematical operation
#include<stdio.h>
void main(){
    //declaring float type variables
    float number1, number2, sum, sub, mul, div;
    
    //declaring charater type variable
    char choice;
    
    //displaying message to input the 
    printf("Enter the first number: ");
    //storing data into variable number1
    scanf("%f",&number1);

    //displaying message to input the 
    printf("Enter the second number: ");
    //storing data into variable number2
    scanf("%f",&number2);

    //displaying message to choose an option
    printf("\nWhich operation do you want to perform: ");
    printf("\nEnter + to add the numbers: ");
    printf("\nEnter - to subtract the numbers: ");
    printf("\nEnter * to multiply the numbers: ");
    printf("\nEnter / to divide the numbers: ");
    
    //storing data into variable choice
    scanf(" %c",&choice);
    
    //if-else condition to choose an operation
    if(choice=='+'){
        sum=number1+number2;
        // .2 is used to show two digits after the point
        printf("\nThe sumation: %.2f",sum);
    } else if(choice=='-') {
        sub=number1-number2;
        printf("\nThe subtraction: %.2f",sub);
    } else if(choice=='*') {
        mul=number1*number2;
        printf("\nThe product: %.2f",mul);
    } else if(choice=='/') {
        div=number1/number2;
        printf("\nThe quetation: %.2f",div);
    } else {
        printf("\nInvalid operation!!!");
    }
}


Tuesday, February 10, 2015

C program to display fibonacci series


The c program given below is able to display the Fibonacci series. Fibonacci series is a series of numbers where the third number = first number + second number.

For example: 0, 1, 2, 3... is a series of all positive integer numbers.

But a Fibonacci series will be like 0, 1, 1, 2, 3, 5, 8, 13, 21 ... where a number is a summation of previous two numbers.

After running the program, you will be asked to provide the limit. That means how many numbers of the series you want to display. For example: if you provide 5 as the limit, then 0, 1, 1, 2, 3 will be displayed from the series.

C codes to display fibnacci series is given below...

//C program to display fibonacci series
#include<stdio.h>

void main(){
//declaring integer type variables
int limit, i, first = 0, second = 1, next=0;

//displaying message to enter the limit
printf("Enter the limit: ");

//storing the limit into a variable
scanf("%d",&limit);

//for-loop to display the fibonacci series
for(i=0; i<limit; i++){
   if(i<1){
       next = i;
   } else {
       first = second;
         second = next;
       next = first + second;
   }

   //displayong the fibonacci series
   printf("%d, ",next);
}

}

Lets see how the above codes work!
Remember all the lines started with double slash (//) will not be executed by the compiler. They will be considered as comments.

Including header file
The line #include<stdio.h> is used to add the header file 'standard input output'. std if for standard, i is for input and o is for output & finally stdio.h goes for standard input output header file.

Starting main function
From the line void main(){ the main function will be started. Sometimes it may be it main().

Declaring integer type variables
In the line int limit, i, first=0, second=1, next=0; , I have declared five integer type variables limit, i, first, second & next. Some of them are initialized also.

Displaying message to user
printf("Enter the limit: "); is used to display a message, that's why the user can realize what to do.

Getting input from keyboard
The line scanf("%d",&limit); will get integer type data from keyboard and will store that into the variable limit.

for-loop to create and to display fibonacci series
The for-loop has started with the line for(i=0; i<limit; i++){. In the for-loop i is initialized to zero (0) and the loop will be continued till the value of i is less than the value of limit. So, if you provide the limit 5 - then the loop will run 5 times when the value of i is 0, 1, 2, 3 & 4. In every loop the value of i will increase by 1 as i++ is given there.

Let consider a real example, so that you can understand the above program more deeply.

» Step 1
When you will run the program then a message will be displayed like...
Enter the limit:

for example if you provide the limit 7, then 7 will be stored into the variable limit by the line scanf("%d",&limit);

Now in the for-loop, i is initialized to 0 what is less than the value of limit. So the for-loop will run. The value of i will be increased by 1 and the if-else condition will be executed lied inside the for-loop.

if(i<1) condition is true, so next=i; operation will be performed and the value from i will be stored into the variable next. In this case the else condition will not be executed and the line printf("%d, ",next); will be executed. As there is 0 in the variable next now, so 0 will be printed with a comma (,).

» Step 2
Again the condition of the for-loop will be checked. As there is 1 in the variable i that is less than than the value of limit (7), so the if condition [if(i<1)] will be checked. In this case the if-condition is false, so the else-condition will be executed.

Inside the else condition there is...
     else {
       first = second;
         second = next;
       next = first + second;
   }

Now we know- first=0, second=1 and next=0
After executing the else condition we will get- first=1, second=0 and next=1+0=1

So, 1 will be printed just after 0, and now on the display there will be 0, 1,

» Step 3
As i=2, so the for-loop will be executed and if condition will be checked again. The if-condition is false, so the else will be executed and we will get...

first=0, second=1 and next=0+1=1

So, another 1 will be printed after 0, 1, and the series will be 0, 1, 1,

» Step 4
Now we have i=3, for-loop will be executed and if-condition will be denied. Again else condition will be executed and we will get...

first=1, second=1, next=1+1=2

So, 2 will be printed after the existing series and the series will be 0, 1, 1, 2,

» Step 5
As i=4 now, so the for-loop will be executed and the if-condition will be denied. So we will get...

first=1, second=2, next=1+2=3

So, 3 will be printed and the series will be 0, 1, 1, 2, 3,

» Step 6
We have i=5 and we will get...

first=2, second=3, next=5

So, 5 will be printed after the series like 0, 1, 1, 2, 3, 5,

» Step 7
We have i=6 and we will get

first=3, second=5, next=3+5=8

so, the series will be 0, 1, 1, 2, 3, 5, 8,

» Step 8
Now we have i=7 and there is 7 inside limit, so the condition for(i=0; i<limit; i++) is false and the loop will not run anymore. Finally, the program will output 0, 1, 1, 2, 3, 5, 8, and will stop.

Advertisement


C program to check a number whether it is prime or not

The c program given below is able to check a number whether it is prime or not. After running the program, first of all you will be asked to provide a number. After providing the number, a for-loop will run to check the number if it is divisible by 2 or any other number.

The if-statement lying inside the for-loop will check if the number is divisible by another number except 1 and the provided number. If the if-statement found that the provided number is divisible by another number except 1 and the same number then a zero will be stored into the variable signal. In the next step the for-loop will be stopped using the statement break;

Finally the result will be displayed using if-else condition.
//c program to check a number whether it is prime or not
#include<stdio.h>
void main(){
    //declaring integer type data
    int number, i, signal=1;

    //displaying message to input a data
    printf("Enter a number: ");

    //getting input into the variable number
    scanf("%d",&number);

    //for-loop to check whether the number is divisible
    for(i=2; i<=number/2; i++){
        if(number%i==0){
            signal = 0;
            break;
        }
    }

    //displaying the result using if-else condition
    if(signal==1){
        printf("\n%d is a prime number\n",number);
    } else {
        printf("\n%d is not a prime number\n",number);
    }
}



Sunday, February 8, 2015

C program to insert data inside of an array

The c program given below is able to insert a new data inside of an array. First of all you will be asked to enter the limit. That means how much data you want to store in the array. For example: you want to store 5 data inside the array and your data are 1, 2, 3, 4 & 5.

So, when you will provide the limit 5, then you will be asked to provide the data. After providing the data 1, 2, 3, 4, & 5; now obviously a[0]=1, a[1]=2, a[2]=3, a[3]=4 and  a[4]=5.

Now our goal is to insert a new data inside the array. For example: we want to insert 7 in the second position. Then the value of a[1] will be 7.
inserting data in an array,array,array in c
#include<stdio.h>
void main(){
    //declaring integer type array and variables
    int a[10], n, i, j, k, item;

    //displaying message to enter the limit
    printf("Enter a limit: ");

    //storing the limit into the variable n
    scanf("%d",&n);

    //message to input the data
    printf("\nEnter the data: ");

    //for-loop to input data into the array
    for(i=1; i<=n; i++){
        scanf("%d",&a[i]);
    }

    //message before displaying the data
    printf("\nData before inserting: ");

    //for-loop to display the data
    for(i=1; i<=n; i++){
        printf("%d, ",a[i]);
    }

    //transfering data to j that stored into n
    j=n;

    //message to enter the position
    printf("\n\nEnter position: ");

    //storing data into k
    scanf("%d",&k);

    //while-loop to shift the data
    while(j>=k){
        a[j+1] = a[j];
        j=j-1;
    }

    //message to enter the item
    printf("\nEnter the item: ");

    //storing item into the variable item
    scanf("%d",&item);

    //transferring the data to a[k] from item
    a[k] = item;

    //increasing the value of n
    n = n+1;

    //message before displaying the data
    printf("\n\nThe data now: ");

    //for-loop to display the data
    for(i=1; i<=n; i++){
        printf("%d, ",a[i]);
    }
}



C program to delete a data from an array and to shifting the rest

The c program given below will store some data in an array, later a data will be deleted from the array and finally left-shifting will be performed to rearrange the array.

After running the program, you will be asked to provide the limit. That means how many data you want to store into the array. After providing the limit, you will be asked to provide the data.

By the 10th line the limit will be stored into the integer type variable n and in the 16th line a for-loop has started to store the data into the array a[i]. In the for-loop there is a condition i<=n, that means the loop will continue till the condition be satisfied.
deleting data from array,left shifting data in array,working with array
#include<stdio.h>
void main(){
    //declaring array and variable
    int a[20], n, i, j;

    //displaying a message
    printf("Enter a limit: ");

    //getting input into the variable n
    scanf("%d",&n);

    //message to input data
    printf("\n\nEnter the data to store: ");

    //for loop to input data into the array
    for(i=1; i<=n; i++){
        scanf("%d",&a[i]);
    }

    //displaying a message
    printf("\n\nThe stored data is: ");

    //displaying the data from the array
    for(i=1; i<=n; i++){
        printf("%d, ",a[i]);
    }


    //displaying message
    printf("\n\nEnter the index of array you want to delete: ");
    scanf("%d",&j);

    a[j]=0;

    //displaying message
    printf("\n\nStored data after deleting: ");

    //displaying the data from the array
    for(i=1; i<=n; i++){
        printf("%d, ",a[i]);
    }

    //for loop for shifting
    for(i=j; i<=n-1; i++){
        a[i]=a[i+1];
    }

    //displaying message
    printf("\n\nStored data after shifting: ");
    for(i=1; i<n; i++){
        printf("%d, ",a[i]);
    }

    //printing two new line
    printf("\n\n");
}


Sunday, February 1, 2015

Java program to understand the continue statement

The program given below will print the numbers between 0-50 skipping the numbers between 11-39. There is a for loop with the condition i<=50; to print the numbers from 0-50, but inside the for loop there is an if statement with the condition i>10&&i<40. Inside the if statement there is another statement continue;.

That's why the numbers from 11 to 39 will be skipped depending on the condition i>10&&i<40. Actually after printing the number till 10, the program will not print the next numbers continuously till it found 40 in the loop.
public class ContinueTest{
 public static void main(String [] args){
  //for loop to print the number between 0-50
  for(int i=0; i<=50; i++){
   //if statement ti check the condition
   if(i>10&&i<40){
    //statement to continue the loop depending on the condition
    continue;
   }
   //displaying the numbers according to the conditions
   System.out.print(i+", ");
  }
 }
}