Tuesday 19 February 2013

Armstrong number


Write a java script for an ARMSTRONG number using WHILE loop

<html>
<head><TITLE></TITLE>
<script language="JavaScript">
var b,z,c=0;
var a=prompt("Enter a number");
z=a;
while(z>0)
{
b=z%10;
c=c+(b*b*b);
z=parseInt(z/10);
}
if(a==c)
alert("given no is amstrong number");
else
alert("given no is not an amstrong number");
</script>
</head>
<body></body>
</html>

palindrome


Write a program for PALINDROME  using DO-WHILE loop

<html>
<script language="javascript">
var a;
var b=0;
var temp;
a=parseInt(prompt("enter a no."));
temp=a;
do
{
b=b*10;
b=b+parseInt(a%10);
a=parseInt(a/10);
}while(a>0);
document.write(b)
if(temp==b)
{
 document.write("the given no is palindrome");
}
else
{
 document.write("the given no is not a palindrome");
}
</script>
</html>

output

enter a no:
1221
the given no is palindrome

enter a no:
1251
the given no is not a palindrome

reverse num

write a java script to display reverse of a given number using WHILE , DO-WHILE  loop

WHILE:

<html>
<script language="javascript">
var a;
var b=0;
a=parseInt(prompt("enter a no."));
while(a>0)
{
b=b*10;
b=b+parseInt(a%10);
a=parseInt(a/10);
}
document.write("The reverse of a given number is:" +b)
</script>
</html> 

OUTPUT

enter a no.
1907
The reverse of a given number is:7091




DO-WHILE:

<html>
<script language="javascript">
var a;
var b=0;
a=parseInt(prompt("enter a no."));
do
{
b=b*10;
b=b+parseInt(a%10);
a=parseInt(a/10);
}while(a>0);
document.write("The reverse of a given number is:" +b)
</script>
</html>

OUTPUT:
enter a no.
3492

the reverse of a given number is:2943

Break the for loop

Write a java script to break the for loop


<!DOCTYPE html>
<html>
<body>
<script>
names=["Geetha","Siri","Rani","Lakshmi"];
for (var i=0;i<names.length;i++)
{
document.write(names[i] + "<br>");
}
</script>
</body>
</html>


Output:


Geetha
Siri
Rani
Lakshmi

Thursday 7 February 2013



Program to let the first letter of  the program float to the left
<!DOCTYPE html>
<html>
<head>
<style>
span
{
float:left;
width:0.7em;
font-size:400%;
font-family:algerian,courier;
line-height:80%;
color:green;
}
</style>
</head>

<body>
<p>
<span>T</span>his is some text.
This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.

</p>

<p>
In the paragraph above, the first letter of the text is embedded in a span element.
The span element has a width that is 0.7 times the size of the current font.
The font-size of the span element is 400% (quite large) and the line-height is 80%.
The font of the letter in the span will be in "Algerian".
</p>

</body>
</html>

OUTPUT:


Wednesday 6 February 2013

Focus the image in HTML


 CSS Image Opacity / Transparency

Example 1 - Creating a Transparent Image
The CSS3 property for transparency is opacity.
First we will show you how to create a transparent image with CSS. 
Syn:
Look at the following CSS:
img
{
opacity:0.4;
filter:alpha(opacity=40); /* For IE8 and earlier */
}

IE8 and earlier use filter:alpha(opacity=x). The x can take a value from
 0 - 100. A lower value makes the element more transparent.
Example 2 - Image Transparency - Hover Effect
img
{
opacity:0.4;
filter:alpha(opacity=40); /* For IE8 and earlier */
}
img:hover
{
opacity:1.0;
filter:alpha(opacity=100); /* For IE8 and earlier */
}

             The first CSS block is similar to the code in Example 1. In addition, we have added what should happen when a user hover over one of the images. In this case we want the image to NOT be transparent when the user hover over it.

The CSS for this is: opacity=1.

IE8 and earlier: filter:alpha(opacity=100).
When the mouse pointer moves away from the image, the image will be transparent again.

Example 3 - Text in Transparent Box
The source code looks like this:
<html>
<head>
<style>
div.background
  {
  width:500px;
  height:250px;
  background:url(klematis.jpg) repeat;
  border:2px solid black;
  }
div.transbox
  {
  width:400px;
  height:180px;
  margin:30px 50px;
  background-color:#ffffff;
  border:1px solid black;
  opacity:0.6;
  filter:alpha(opacity=60); /* For IE8 and earlier */
  }
div.transbox p
  {
  margin:30px 40px;
  font-weight:bold;
  color:#000000;
  }
</style>
</head>

<body>

<div class="background">
<div class="transbox">
<p>This is some text that is placed in the transparent box.
This is some text that is placed in the transparent box.
This is some text that is placed in the transparent box.
This is some text that is placed in the transparent box.
This is some text that is placed in the transparent box.
</p>
</div>
</div>

</body>
</html>

           First, we create a div element (class="background") with a fixed height and width, a background image, and a border. Then we create a smaller div (class="transbox") inside the first div element. The "transbox" div have a fixed width, a background color, and a border - and it is transparent. Inside the transparent div, we add some text inside a p element.








Filter in CSS


CSS FILTER:
                The CSS filter property provides for effects like blurring or color shifting on an element’s rendering before the element is displayed. Filters are commonly used to adjust the rendering of an image, a background, or a border.
·         Initial value:          none
·         Applies to:  graphics and container elements
·         Inherited :   no
·         Media:                  visual
·         Computed valueas specified
·         Animatable: yes
Syntax
filter: <filter-function> [<filter-function>]* | none
Examples
Examples of using the predefined functions are shown below. See each function for a specific example.
.mydiv { filter: grayscale(50%) }
/* gray all images by 50% and blur by 10px */
img {
  filter: grayscale(0.5) blur(10px);
}
Examples of using the URL function with an SVG resource are shown below.
.target { filter: url(#c1); }

.mydiv { filter: url(commonfilters.xml#large-blur) }
Functions
To use the CSS filter property, you specify a value for one of the following functions. If the value is invalid, the function returns "none." Except where noted, the functions that take a value expressed with a percent sign (as in 34%) also accept the value expressed as decimal (as in 0.34).
blur(radius)
Applies a Gaussian blur to the input image. The value of ‘radius’ defines the value of the standard deviation to the Gaussian function, or how many pixels on the screen blend into each other, so a larger value will create more blur. If no parameter is provided, then a value 0 is used. The parameter is specified as a CSS length, but does not accept percentage values.
filter: blur(5px)
<svg height="0" xmlns="http://www.w3.org/2000/svg">
  <filter id="svgBlur" x="-5%" y="-5%" width="110%" height="110%">
    <feGaussianBlur in="SourceGraphic" stdDeviation="5"/>
  </filter>
</svg>

brightness(amount)
Applies a linear multiplier to input image, making it appear more or less bright. A value of 0% will create an image that is completely black. A value of 100% leaves the input unchanged. Other values are linear multipliers on the effect.
filter: brightness(0.5)


contrast(amount)
Adjusts the contrast of the input. A value of 0% will create an image that is completely black. A value of 100% leaves the input unchanged. 
filter: contrast(200%)

drop-shadow(<shadow>)
Applies a drop shadow effect to the input image. The function accepts a parameter of type <shadow> (defined in CSS3 Backgrounds), with the exception that the ‘inset’ keyword is not allowed. This function is similar to the more established box-shadow property; the difference is that with filters, some browsers provide hardware acceleration for better performance. 
<offset-x> <offset-y> (required)          
This are two <length> values to set the shadow offset. <offset-x> specifies the horizontal distance. <offset-y> specifies the vertical distance. If both values are 0, the shadow is placed behind the element (and may generate a blur effect if <blur-radius> and/or <spread-radius> is set).
<blur-radius> (optional)
This is a third <length> value. The larger this value, the bigger the blur, so the shadow becomes bigger and lighter.
<spread-radius> (optional)
This is a fourth <length> value. Positive values will cause the shadow to expand and grow bigger, negative values will cause the shadow to shrink. 
<color> (optional)
          It provides the color.

grayscale(amount)
Converts the input image to grayscale. The value of ‘amount’ defines the proportion of the conversion. A value of 100% is completely grayscale. A value of 0% leaves the input unchanged. 
filter: grayscale(100%)




hue-rotate(angle)
Applies a hue rotation on the input image. The value of ‘angle’ defines the number of degrees around the color circle the input samples will be adjusted. A value of 0deg leaves the input unchanged. If the ‘angle’ parameter is missing, a value of 0deg is used. Maximum value is 360deg.
filter: hue-rotate(90deg)

invert(amount)
Inverts the samples in the input image. The value of ‘amount’ defines the proportion of the conversion. A value of 100% is completely inverted. A value of 0% leaves the input unchanged. 
filter: invert(100%)
opacity(amount)
Applies transparency to the samples in the input image. The value of ‘amount’ defines the proportion of the conversion. A value of 0% is completely transparent. If the ‘amount’ parameter is missing, a value of 100% is used. This function is similar to the more established opacity property.
filter: opacity(50%)

saturate(amount)
Saturates the input image. The value of ‘amount’ defines the proportion of the conversion. A value of 0% is completely un-saturated. A value of 100% leaves the input unchanged.  If the ‘amount’ parameter is missing, a value of 100% is used. 
filter: saturate(3%)

sepia(amount)
Converts the input image to sepia. The value of ‘amount’ defines the proportion of the conversion. A value of 100% is completely sepia. A value of 0 leaves the input unchanged.
filter: sepia(100%)


Combining functions
You may combine any number of functions to manipulate the rendering. The following example enhances the contrast and brightness of the image.
filter: contrast(175%) brightness(3%)





Tuesday 5 February 2013

Pseudo elements in CSS


CSS PSEUDO elements:
CSS pseudo-elements are used to add special effects to some selectors. You do not need to use Javascript or any other script to use those effects.
Syntax:
selector:pseudo-element {property: value}
CSS classes can also be used with pseudo-elements:
selector.class:pseudo-element {property: value}
There are following most commonly used pseudo-elements:
Value
Description
:first-line
Use this element to add special styles to the first line of the text in a selector.
:first-letter
Use this element to add special style to the first letter of the text in a selector.
:before
Use this element to insert some content before an element.
:after
Use this element to insert some content after an element.
The :first-line pseudo-element
Following is the example which demonstrates how to use :first-line element to add special effect to the first line of elements in the document .
<style type="text/css">
p:first-line { text-decoration: underline; }
p.noline:first-line { text-decoration: none; }
</style>
<p class="noline"> This line would not have any underline
because this belongs to nline class.</p>

<p>The first line of this paragraph will be underlined
as defined in the CSS rule above. Rest of the lines in this
paragraph will remain normal. This example shows how to use
:first-line pseduo element to give effect to the first line
of any HTML element.</p>
This will produce following black link:
This line would not have any underline because this belongs to noline class.

The first line of this paragraph will be underlined as defined in the CSS rule above. Rest of the lines in this paragraph will remain normal. This example shows how to use :first-line pseduo element to give effect to the first lines of any HTML element.
The :first-letter pseudo-element
Following is the example which demonstrates how to use :first-letter element to add special effect to the first letter of elements in the document .
<style type="text/css">
p:first-letter { font-size: 3em; text-color:red; }
p.normal:first-letter { font-size: 10px; }
</style>
<p class="normal"> First character of this paragraph will
be normal and will have font size 10 px;</p>

<p>The first character of this paragraph will be 3em big
and in red color as defined in the CSS rule above. Rest of the
characters in this paragraph will remain normal. This example
shows how to use :first-letter pseduo element to give effect to
the first characters  of any HTML element.</p>
This will produce following black link:
First character of this paragraph will be normal and will have font size 10 px;
The first character of this paragraph will be 3em big and in red color as defined in the CSS rule above. Rest of the characters in this paragraph will remain normal. This example shows how to use :first-letter pseduo element to give effect to the first characters of any HTML element.
The :before pseudo-element
Following is the example which demonstrates how to use :before element to add some content before any element .
<style type="text/css">
p:before
{
content: url(/images/bullet.gif)
}
</style>
<p> This line will be preceded by a bullet.</p>
<p> This line will be preceded by a bullet.</p>
<p> This line will be preceded by a bullet.</p>
This will produce following black link:
  • ·        This line will be preceded by a bullet.
  • ·        This line will be preceded by a bullet.
  • ·        This line will be preceded by a bullet.


The :after pseudo-element
Following is the example which demonstrates how to use :after element to add some content after any element .
<style type="text/css">
p:after
{
content: url(/images/bullet.gif)
}
</style>
<p> This line will be succeeded by a bullet.</p>
<p> This line will be succeeded by a bullet.</p>
<p> This line will be succeeded by a bullet.</p>
This will produce following black link:
This line will be succeeded by a bullet.   .
This line will be succeeded by a bullet.   .
This line will be succeeded by a bullet. .