Professional Documents
Culture Documents
Style Sheets:
a style sheet is a file or form that defines the layout of a document. Style sheets are
useful because you can use the same style sheet for many documents. style sheets are also
called templates.
Introduction:
• Cascading Style Sheets, or CSS, are a series of instructions that specify how
markup elements should appear on a Web page.
• Cascading Style Sheets (CSS) is a style sheet language used to describe the
presentation semantics (the look and formatting) of a document written in a
markup language.
Features of CSS:
• CSS allows “separation” between the information contained in a document and its
presentation.
• Changes in the presentation can be made without disturbing the information of the
document.
• Style sheet allows user to decide the style of presentation and it is defined in
separate file.
• Single style sheet used for all the pages of the web site and all the pages will have
consistent look and feel.
Syntax of CSS:
CSS Rules
A CSS rule defines the appearance attributes that HTML will acquire and so change the
display of the document content in the browser.
1. Selectors: Selectors are string identifiers that defines to what HTML element the rule
is applied. A selector can be an HTML tag, a class selector or an ID selector.
After the selector has been specified, the definition provides the properties and values to
be used with the selector.
CSS Types:
• CSS effects document changes as style rules. Style rules can be implemented in three
ways:
1. Inline:
defines style rules set within individual HTML tags using the style
attribute. Inline styles rules override any other influencing style rule. For example:
Syntax:
2. Embedded:
defines style rules set within the HTML <HEAD> section of a document,
using the STYLE tag. Embedded styles rules can include variety of HTML
elements which will be applied to all the specified tags that are used within the
<BODY> of the document. For example:
Syntax:
3. External:
defines the use of a separate text file containing the style rules. External
style files have a css file extension name. External style sheets are implemented
with the use of the <LINK> tag, and provide formatting standards that can be
applied as a template to any number of documents at a Web site. The style is
called from within the HTML document using the <LINK> tag:
syntax:
Example:
<html>
<head>
<title>Document Title</title>
<link href="my_style_sheet.css" rel="stylesheet" type="text/css">
</head>
</html>
Selectors
1. Simple Selector
• The simple selector is used for applying style to a single element to which
the property and value is applied to it.
• Example:
<style type= “text/css”>
H1
{
Font-family:arial;
Font-size:20pt;
Font-color:red;
}
</style>
2. Universal Selector
• Universal selector is used to apply the property and value to all the
elements in the document which represent the universal selector symbol.
• Example:
<style type= “text/css”>
*{
Font-family:arial;
Font-size:20pt;
Font-color:red;
}
</style>
3. Class selector
4. Generic selector
Important Notes:
• The <P> tag must include a close tag, </P>, when used with CSS.
• color
• letter-spacing
• text-align
• text-decoration
• text-indent
• text-transform
• background-color
• background-image
• background-repeat
• background-position
• background-attachment
• font-family
• font-size
• font-style
• font-variant
• font-weight
Box Model:
• Every block element in CSS is effectively inside a box, and can have margins,
padding and borders applied to it.
• Box widths can be specified in absolute values (e.g. px) or in relative values,
usually:
em - width values relative to the size of the font in ems
percentage - width values relative the containing box’s content region
• The root (or top-most) element’s containing box is effectively the browser
window.
Border properties
i. border-style
ii. border-color
iii. border-width
• Borders can be applied to any block element
• Borders always come outside the padding area, but inside the margin area.
• Border properties cannot have negative values
• If a border is not specified, the default is no-border (i.e. no border appears and no
space between any margin and padding is allocated for a border)
• Border properties can be defined independently on top, right, bottom and left, or
all-at-once using CSS shorthand
i. margin-bottom
ii. margin-left
iii. margin-right
iv. margin-top
i. padding-bottom
ii. padding-left
iii. padding-right
iv. padding-top
• Padding defines the space around elements inside the border; i.e between the
border and the content itself
• Padding properties cannot have negative values
• Padding properties do not affect the position of background elements (graphics
and/or colours) in the containing block element; only the position of content.
• Padding properties can be defined independently on top, right, bottom and left, or
all-at-once using CSS shorthand
Floating
• float property allows element boxes to be shifted to the right or left on the current
line
– Floated boxes are block boxes
– Floated boxes are “pulled out” of the normal flow and repositioned
– Must have explicit width
– May overlap other boxes
• clear property specifies which side(s) of an element should NOT be adjacent to a
floating box that is specified earlier in the document
• Setting the float property to left or right causes a box to be taken out of its position
in the normal flow and moved as far left or right as possible.
Positioning
• position property:
– static – box is positioned according to normal flow
– relative – box is positioned relative to where it would have been placed in
the normal flow
– absolute – box is positioned relative to its containing block; these boxes are
taken out of flow
– fixed – box is fixed in relation to the viewport (a browser window or a
printed page)
Variables
• Naming conventions
• Global
o Global variables are declared simply by assigning a value:
x = 10;
• Local
o Local variables are declared inside a function:
var x;
• Undefined vs. Null-value
JavaScript Operators
• Associativity:
– Assignment, conditional, and prefix unary operators are right associative:
equal-precedence operators are evaluated right-to-left:
– Other operators are left associative: equal-precedence operators are
evaluated left-to-right
• Relational operators <, >, <=, >= convert both operands to Number
– Exception: If both operands are String, no conversion is performed and
lexicographic string comparison is performed
JavaScript Literals:
Types of literals:
1. Numeric literals
• Integers
• Floating –point numbers
2. String literals
• String literals is zero (or) more character enclosed in double (“ “) (or) single
( ‘ ‘) quotation marks.
3. Boolean literals
• Boolean literal have two type of value.
i. True
ii. false
Functions in JavaScript
• Declared within other functions. These are called “inner functions” and are the
main idea behind closures in JavaScript.
• Built-in functions are almost completely concerned with validating argument types
which are commonly passed into functions or methods as well as converting
variables to and from these types.
• This includes specifics such as NaN(), infinity(), and undefined(), as well as
functions for encoding and decoding data.
• Functions can be created through several different techniques, and since JavaScript
uses first-class functions, they are treated as objects.
• Function objects have properties, and can be passed around and used just like any
other object.
• Variables, literals, and objects can be passed as arguments.
• The argument list is an array with the same name.
• Overloading is not implemented, but can be simulated
• Function declaration syntax:
function validate()
{
alert(“this is example”);
}
• Recursive functions
– Recursion (function calling itself, either directly or indirectly) is supported
– C++ static variables are not supported
– Order of declaration of mutually recursive functions is unimportant (no
need for prototypes as in C++)
Flow Control
If…else
While
Do-while
For
Return
Break
Switch
Object Introduction
• An object is a set of properties
• A property consists of a unique (within an object) name with an associated value
• The type of a property depends on the type of its value and can vary dynamically
Object Creation:
• A constructor is a function
– When called via new expression, a new empty Object is created and passed
to the constructor along with the argument values
– Constructor performs initialization on object
• Can add properties and methods to object
• Can add object to an inheritance hierarchy
• The Object() built-in constructor
– Does not add any properties or methods directly to the object
– Adds object to hierarchy that defines default toString() and valueOf()
methods (used for conversions to String and Number, resp.)
Property Creation
• Special form of for statement used to iterate through all properties of an object:
• The JavaScript object dot notation is actually shorthand for a more general
associative array notation in which Strings are array indices:
Object Methods
Object Constructors
• User-defined constructor is just a function called using new expression:
JavaScript Arrays
• The Array built-in object can be used to construct objects with special properties
and that inherit various methods
• Value of length is not necessarily the same as the actual number of elements
MathObject
Methods of the StringObject
Date Object:
Booleanand NumberObjects
JavaScript Global Functions
Java Script String Object:
Property Description
constructor A reference to the function that created the object
length Returns the number of characters in a string
prototype Allows you to add properties and methods to the object
When you run the debugger for the first time, the IDE first checks if you have the
appropriate resources and extensions installed in your browser.
• Internet Explorer
• Firefox
Internet Explorer
1. Start the debugger by right-clicking your project in the Projects window and
choosing Debug.
2. In the dialog box that displays, select the Server side Java with client side
JavaScript in the selected browser option. Then select Internet Explorer.
3. Click Debug. When you select the client-side debugging option for Internet
Explorer and click Debug, the IDE first ensures that you have the Active
Scripting debugger framework installed. If it have not been installed, you are
prompted to download and install the framework.
Your browser is launched to the location on Microsoft's website where you can
download the framework. Download and install the framework.
4. Once you receive confirmation that the Active Scripting debugger framework has
been installed, return to the IDE and click OK. The IDE checks if you have the
NetBeans Internet Explorer extension registered in your browser. If not, a dialog
displays, prompting you to enable the IDE to install the NetBeans Internet
Explorer extension.
5. Click OK. The IDE registers the extension in your browser, the debugging session
is initiated, and the welcome page of the application you are running the
debugging session on displays in your browser.
6. Return focus to the IDE. The debugger toolbar is displayed above the editor. All
icons of the toolbar are activated when the code becomes suspended. The project
index page opens in the IDE's editor.
By default, numerous windows are activated in the lower region of the IDE,
including the Watches, Local Variables, and Call Stack windows. The debugger
console initially displays in the Output window, indicating that a debugging
session has been started. The debugger console can be used during a debugging
session to show evaluation errors, thrown exceptions, and other information.