Thursday 21 March 2013

Cascading Style Sheet (CSS)

CSS is recommended to design the layout of the page including position of the element, appearance of the element n HTML. CSS can  be specified as inline CSS, Internal CSS and External CSS.
  • Inline CSS : Specifying a CSS style by string style attribute of HTML elements without defining it separately is called as Inline CSS. 
Eg: The following example changes font and color of the heading level h1 using Inline CSS.

<!doctype html>
<html>
<body>
<h1 style= "font-family:arial black; color:blue">
Inforica Pvt lmd
</h1>
</body>
</html>
  • Internal CSS : When CSS styles are defined within the head section then it is called as Internal CSS. While defining CSS in the head section. CSS style will have three main parts- Selector, Property and Value. Selector is used to specify the HTML element for which you are defining the style. property is used to specify the CSS property you want to set and value is used to specify the value for CSS property. Property and its value must be separated by colon and multiple properties must be separated by semicolon.
Eg: The following example defines styles for the elements h1 and h2 as internal CSS.

<!doctype html>
<html>
<head>
<style type = "text/CSS">
<h1>
{
font-family:arial black; color:blue"
}
<h2>
{
font-family:times new roman; color:red"
}
</style>
</head>
<body>
<h1> Inforica Pvt lmt </h1>
<h2> Inforica Pvt lmt </h2>
<h1> Inforica Pvt lmt </h1>
<h1> Inforica Pvt lmt </h1>
</body>
</html>
  • External CSS : Defining the CSS styles in seperate files with extention .CSS is called as external CSS. Advantages of external CSS is that they can be used in any HTM document. To add the reference the External CSS file use style element with src attributes or the link element withen the head section.
Syntax:  <style src = "Filename.css">
             <link rel = "stylesheet" type="text/css">
             href="Filename.css"


Partial Classes

  • They are introduced in C# 2.0 which allows us to define a class on multiple files ie we can physically split a class and put it into different files.

          parts.cs                                                          parts1.cs
         class parts                                                       partial class part{
        {                                                                      method1()
         method1()                                                       method2()
         method2()                                                       }
         method3()                                                      parts2.cs
        method4()                                                       partial class parts{                                           
        }                                                                    method3()
                                                                              method4()
                                                                              }
  • In the above case, the class which is defined in left hand side is redefined using the approach of partial classes wherein in this approach the class is physically separated parts logically it is one single unit ie in both the two cases when we create object of class arts we can access all the methods of the class.
  •  if  we want to define partial class in all the files the class name must be same to tell that this is one class only and moreover we need to use a partial modifier on the class in each and every file.
  • In case of partial class if we want to inherit the class from any other class it will be sufficient if we perform inheritance in one file so that it takes to a complete class
The advantages if defining partial classes are:
  • It allow splitting huge volumes of code into separate files so that managing becomes much easier.
  • Multiple programmers can work on the same class at the same time.