Friday, 17 October 2014

how to use DIV, ID and Classes

A <div> divides a page into separate sections. Simple as that. It’s how you tell these sections how to behave that makes the magic happen. You can adjust margin, padding, background and font colors, borders, width, height and a lot of other basic parameters without much fuss.  They are very handy for keeping things tidy.
With the use of CSS Classes you can have more than one style per HTML element. So if you want one block of text to be white and another block to be grey, it’s as simple as adding an extension to your CSS code and make sure you specify this extension in your HTML.
Now, IDs differ from Classes in the way that retail products differ from their serial numbers. So you may set up a Class that is used in several elements, but you may only have one unique ID in any one HTML document for things to function properly.
In this example he has created a simple page with HTML:

  1. <html>
  2. <head>
  3. <link rel="stylesheet" type="text/css" href="style.css">
  4. </head>
  5. <body>
  6. <div id="navigation">
  7. <ul>
  8. <li><a href="index.html">Home</a></li>
  9. <li><a href="about.html">About</a></li>
  10. <li><a href="portfolio.html">Portfolio</a></li>
  11. <li><a href="contact.html">Contact</a></li>
  12. </ul>
  13. </div>
  14. </body>
  15. </html>

And then he has styled it with CSS:


  1. #navigation {
  2. width: 100%;
  3. height: 60px;
  4. background: #3e3e3e;
  5. position: absolute;
  6. top: 0;
  7. left: 0;
  8. }
  9. #navigation ul {
  10. margin: 0;
  11. list-style-type: none;
  12. }
  13. #navigation a {
  14. color: #FFF;
  15. text-decoration: none;
  16. }
  17. #navigation a:hover {
  18. color: #1dbaf8;
  19. }
  20. #navigation ul li {
  21. float: left;
  22. line-height: 60px;
  23. margin-right: 10px;
  24. }

Thursday, 16 October 2014

fixed header with css

Begins with a basic web page that has a set width and a small header that matches the width set up at the top of the page. so we just need to make that header follow us as we scroll down the page. Here is what the code looks like in the beginning.

  1. <head>
  2. <style type="text/css">
  3. body{
  4. margin:0px;
  5. background:#000;
  6. }
  7. .header {
  8. height:50px;
  9. background:#F0F0F0;
  10. border:1px solid #CCC;
  11. width:960px;
  12. margin:0px auto;
  13. }
  14. .content {
  15. width:960px;
  16. background: #F0F0F0;
  17. border: 1px solid #CCC;
  18. height: 2000px;
  19. margin: 20px auto;
  20. }
  21. </style>
  22. </head>
  23. <body>
  24.  
  25. <div></div>
  26.  
  27. <div></div>

Changing the header width to 960px; will create the proper size, but it still needs to be positioned correctly. To do this, we add a property of margin: 0px auto; to the header and then create a new class .header-cont { width:100%; position:fixed; top:0px; }. This then wraps the header division to apply the two classes to it. You can also now remove the top: andposition: properties from the header


  1. <style type="text/css">
  2. body{
  3. margin:0px;
  4. background:#000;
  5. }
  6. .header-cont {
  7. width:100%;
  8. position:fixed;
  9. top:0px;
  10. }
  11. .header {
  12. height:50px;
  13. background:#F0F0F0;
  14. border:1px solid #CCC;
  15. width:960px;
  16. margin:0px auto;
  17. }
  18. .content {
  19. width:960px;
  20. background: #F0F0F0;
  21. border: 1px solid #CCC;
  22. height: 2000px;
  23. margin: 70px auto;
  24. }
  25. </style>
  26. </head>
  27. <body>
  28.  
  29. <div class="header-cont">
  30. <div></div>
  31. </div>
  32.  
  33. <div></div>

Wednesday, 4 June 2014

C# Tutorial-Basics- String Formatting

Building strings from variables is a very common task in programming. 
C# has the string.Format() method to format strings.
Some dynamic languages like Perl, PHP or Ruby support variable interpolation. 
Variable interpolation is replacing variables with their values inside string literals.
 C# does not allow this. It has string formatting instead.
using System;

public class StringFormatting
{
    static void Main()
    {
        int age = 34;
        string name = "Kshatriya";
        string output;

        output = string.Format("{0} is {1} years old.", 
            name, age);
        Console.WriteLine(output);
    }
}
Strings are immutable in C#.
We cannot modify an existing string. 
We must create a new string from existing strings and other types. 
In the code example, we create a new string. We also use values from two variables.

int age = 34;
string name = "Kshatriya";
string output;
Here we declare three variables.

output = string.Format("{0} is {1} years old.", 
    name, age);
We use the Format() method of the built-in string class. 
The {0}, {1} are the places where the variables are evaluated. 
The numbers represent the position of the variable. 
The {0} evaluates to the first supplied variable and the {1} to the second etc.
$ ./stringformatting.exe 
William is 34 years old.
This is the output of the stringformatting.exe program.