MODULE 2 (Updated)
MODULE 2 (Updated)
INTRODUCTION TO CSS
• CSS stands for Cascading Style Sheets. It is a style
sheet language which is used to describe the look and
formatting of a document written in markup language.
• It provides an additional feature to HTML.
• It is generally used with HTML to change the style of
web pages and user interfaces.
• It is a text file with .css extension.
Syntax of CSS
Selector
{
1st property: value
2nd property: value
3rd property: value
.
.
}
Exploring CSS selectors
• Selector is a pattern that is used to select an element to apply the css
style rules.
• Selectors can be used as a condition or a css rule to determine the
elements that match with selector.
• Css rule has two parts:
Selectors
declaration
Types of selectors
• The universal selector
• The type selector
• The class selector
• The id selector
• The child selector
• The descendant selector
• The adjacent sibling selector
• The attribute selector
• The query selector
The Universal selector
• This selector will select all the element that are present in an HTML
document .
• It can be used to apply same rule to all the elements.
• Universal selector is represented by an asterisk symbol (*).
*{}
Example:
*{
Margin : 0;
Padding : 0;
}
Type selector
• This matches all the elements specified in a list with given value to
determine the elements to which the CSS rules are applied.
Example:
h1 , h2 , h3 , p {font family: sans- serif}
Class selector
• Class selector allows you to apply CSS rules to elements that carry
class attribute whose value matches with class attribute specified in
class selector.
• We can use class selector in either 2 ways :
Applying css rule to all the elements that have class attribute of same
value
Applying CSS rule to H1 elements whose class attribute contain intro
as its value.
Example:
<h1 class=“intro”>header</h1>
<h2>heading</h2>
<p>hello</p>
<p>good afternoon</p>
Here first paragraph matches adjacent sibling selector.
But second paragraph does not match.
The attribute selector
CSS attribute selector selects elements on the basis of some specific
attributes or attribute values.
Name syntax Match
Hyphen selector [attribute|=value] Matches if the element
has an attribute with a
value followed by a
hyphen
Existence Selector [attribute] Matches if the element
has a specific attribute
Equality selector [attribute=value] Matches if element has an
attribute with a specific
value.
Space selector [attribute~=value] Matches if element has
attribute with space
separated items that
match with value
Query selector
• Queryselector() and queryselectorAll() methods accept CSS selectors
as parameters and return the matching element node in the
document tree.
Queryselector ()method helps in quering the entire document or a
specified element of the document.
We can use all CSS selectors with this method as parameters.
<style type=“text/css”>
@import url(”myshtylesheet.css”)
H1{color:blue}
</style>
<style type=“text/css”>
@import URI(“mystylesheet.css)
H1 {color:blue}
</style>
In addition to @import rule, the @media rule helps us in applying the style to media
device depending on the type of device a page is displaying.
Some of them Computer screens, printers, television , handhelds, speech synthesizers
and projectors.
<style type=“text/css”>
@media screen
{
Body { font-size:13px}
}
</style>
The Inline Style
• Inline tyle properties are written in single line separated by
semicolon;
• These properties are placed inside style attribute of HTML Element on
which we want to apply.
<p style=“background : blue ; color : red ; border : solid black 1px;”>
Defining inheritance in CSS
• The css properties applied to an element is also inherited by the child
elements of that element.
<div style=“font-family: serif”>
<p> this text is also in serif</p>
</div>
In this case the property applied for div is automatically inherited by
the P element from parent DIV element.
But padding and border properties cannot be inherited.
• Below shows list of attributes that are inherited automatically
properties Description
Border-collapse Represents the border display
Border-spacing Represents the thickness of the border
Caption-side Represents the place of table caption
color Color of text
cursor Represents cursor to be displayed
direction Direction of text.
font Font properties
Empty - cells Specifies whether to Display border and background on empty cells
Font -family Font family of text
Font-stretch Represents text as stretched or condensed.
Font- size Represents the size of text
Font-size-adjust Size of text on the basis of an aspect value.
Font -style Style of text
Font- variant Fonts variant, such as small caps.
Font-weight Represent font as bold.
Letter-spacing Space between characters in a text.
Line-height Height of line
List-style Style of line
List-style-image Represents image as list marker
List style type Type of list marker.
quotes Quotation marks in text
Text-align
Text- indent Indentation of text
Text- transform Transformation of text, such as uppercase , capitalize and lowercase.
White -space Handles space in an element
Word-spacing Represents the spacing between the words in text.
Background and color
Gradients in CSS
• CSS provides various Properties to set the background of a web page.
1) Background- color
2) Background- image
3) Background- repeat
4) Background- attachment
5) Background- position
6) Background- clip
7) Background- origin
8) Background- size
9) Background- quantity
10) Background- spacing
11) Background
Background -color
It takes three values
Color name
Hexadecimal equivalence of color
RGB color value
Content-box
• Specifies the position of background image in relation to the outer
edge of content or inner edge of the padding.
Background -size property
• We can specify size by using any of the following values:
The auto keyword- sets the image to its original size.
Background-size: auto;
Percentage parameter.
Background-size: 50%;
Background- quantity property
• It is used to specify the number of times to repeat an image. It takes
following value:
• The infinite keyword- repeats image infinitely.
Background-quantity : infinite;
• The integer keyword- repeats image specified number of times.
Background-quantity : 5;
Background-spacing property
H1 background-color: RGBA(153,134,117,0.3); }
Exploring gradient properties
Syntax
Linear-gradient(pos,#AAA B, #XXX Y);
Pos-position of first color, which gives direction.
#AAA – specifies the primary color.
B – specifies Percentage rom where the fade begins.
#XXX- specifies secondary color.
Y – specifies percentage from where the fade begins
Font and text styles
Font properties
• Font-family
• Font-size
• Font-size-adjust
• Font-stretch
• Font-style
• Font –variant
• Font-weight
• font
Font-family
Fonts are categorized under Different font families:
Serif
sans-serif
Cursive
Fantasy
monospace
Body {
Font-family : sans serif;
}
Font-size property
• Font-size can be specified in following three different ways
Using absolute value.
Using relative values
Using a percentage value
Absolute values refers to the
• XX-small
• x-small
• Small
• Medium
• Large
• X-large
• Xx-large
• large
Font-size-adjust property
• It is used to change aspect value of text on web page.
• It is the ratio between the font height of lowercase letter and actual
height of font.
p{
Font-size-adjust:0.5;
}
Font-stretch property
It is used to change the width of font.
Font-variant property
• Used to display the font as normal or in
small caps
Font-weight
• Used to specify weight of font, such as boldness or thickness.
• Possible values for font-weight are lighter, normal, bold, bolder and
numbers from 100-900.
Font property
Instead of defining all the properties separately , we can specify the
values of all these properties in font property.
P { font: bold italic 30px verdana ; }
Web font
• Web font allows us to write text in fonts other than those present in
our system.
• Syntax:
@font-face {
font-family: <name>
src : <source>
}
Using text-transform property
Text transform is used to transform text to uppercase , lowercase or
capitalized letters.
• <li><p style=“text-transform: capitalize”>my paragraph<p></li>
• <li><p style=“text-transform: lowercase”>my paragraph<p></li>
• <li><p style=“text-transform: uppercase”>my paragraph<p></li>
• <li><p style=“text-transform: none”>my paragraph<p></li>
Using text- indent property
• It is used to change the indentation of the text in a web page.
<!DOCTYPE html>
<html>
<head>
<style>
div.a {
text-indent: 50px;
text-indent: 2cm;
text-indent: 30%;
}
Using text decoration property
• It is used to decorate text by applying underline, overline, strikeouts,
and blinking effects.
Padding area:
It specifies the area around content area. This is bounded by padding
edge. The padding is transparent
Border area:
A border that goes around the padding and content.
Margin area: specifies the area around border area. Clears an area
outside the border. The margin is transparent
Box model has following types:
• Block-level box: represents a box to show paragraph
• Line-box : represents a box to show a line of text.
• Inline-level box : represents a box to show the words of a line
Padding properties:
Padding(space) in box model specifies the distance between the border
of an element and the content within it.
Padding is effected by the background color of an element.
The shorthand property in padding is used to change all the padding
properties such as padding-top, padding-bottom, padding right and
padding-left.
The syntax to set padding properties is
Padding : value;
• Length
• Percentage
• Auto
#container {
Padding-top:7px;
Padding-left: 25%
Padding-right :auto
Padding- bottom
Border: 2px solid 0000000
}
• Padding property is used to set values for all four directions in box
layout model.
• If the padding property has only one value , then it is applied equally
on all four paddings
• If the padding has two values, the first value is applied to the top and
bottom padding , and the second is applied for right and left padding.
• If the padding has 3 values , the first is for top , second is for right and
left and third is for bottom padding.
• If it has 4 values, then it is top , right, bottom and left
Exploring border properties
• Border specifies a space between the padding and content box
model.
• The syntax to set border is
Border 1px double value;
Border has following properties:
• Border-width
• Border- color
• Border-style
• Border-shorthand
• Border-radius
• border-image
• Border-shadow
Border-width property
Border-top-width property
Border-right-width property
Border-bottom-width property
Border-left-width property
Border-width shorthand property
Border-color property
• It specifies the color of the border.
Border colors are defined using following values:
Name
RGB values
Hexadecimal values
Border-color: value;
Border-color uses different properties for each side, such as
• Border-top-color
• Border-right-color
• Border-bottom-color
• Border-left-color
All the properties takes the following values:
Inherit
Transparent
color
Border-style property
• It indicates the format of the border such as solid, dashed, double.
Syntax:
Border-style: value;
Value used are none, hidden, dotted, dashed, solid, double, groove,
ridge, inset and outset .
Border-style property can be used with four directions
Border-top-style
Border-right-style
Border-bottom-style
Border-left-style
Border-style shorthand
Exploring margin property
Blank area around the border of an element is called margin.
Used to create extra space around the element.
P{
Margin :value;
}
CSS has properties for specifying the margin for each side of an element:
margin-top
margin-right
margin-bottom
margin-left
All the margin properties can have the following values:
Example:
Img { float : left; }
Overflowing of Box Content
• CSS provide various overflow properties to restrict the overflow of
content in an element.
• Overflow properties of CSS
Here :
visible: - indicates that content is not clipped.
Hidden: - indicates that the content is clipped and that no scrolling mechanism should
be provided to view content outside the clipping region
Scroll:- indicates that content is clipped and scrolling mechanism should be displayed
for a box
Auto:- indicates that scrolling mechanism has to be provided to a box, because the
content of this box overflows from its content area.
No-display:- indicates that if the content doesnot fit in the content box, the box is
removed completely.
No-content :- indicates that if the content does not fit in the content box, content is
hidden completely.
Exploring Marquee properties
• Properties that produce marquee effects are:
Marquee-style : it specifies a style to move the content of an element.
Syntax:
marquee-style : scroll | slide | alternate;
Scroll: specifies the moving style in which the element starts moving
from one side , scrolls all the way across and then stops.
Slide: specifies the moving style in which the element starts moving
from one side , scrolls in and stops if no more content available.
Alternate : specifies the moving style in which element starts moving
from both sides alternatively.
• Marquee – loop : determines how often the content moves.
marquee-loop: <non-negative-integer> | infinite ;
}
Exploring the Line Box Model
• It is used to enhance the box model.
• It helps to display elements and text in line with each other.
• It enables us to display first line of an element in specified format or
to display the first character of an element in big font size.
Introduction to
Javascript
Features of javascript:
• Imperactive and structured
• Dynamic text
• Functional
• Prototype based
• Platform independent
Using Javascript in HTML Document
• Script element is used to insert javascript in HTML document.
• When the script element is loaded in browser, it process the content
enclosed with script as Javascript.
• Attributes:
•
We can use javascript in a webpage in following 3 ways:
• In the head element
• In the body element
• As an external script file
Selection statements
If
If-else
switch
The if Statement
Syntax
• if (condition)
{
statements
}
Note that if is in lowercase letters. Uppercase letters (If or IF) will
generate a JavaScript error.
If else statement
If(condition)
{
Statement1
}
Else
{
statement2
}
Switch statement
Syntax:
Switch(expression)
{
Case value1: statement1
break;
Case value2: statement2
break;
Default: default_statement
break
Loop statements
• While
• Do while
• For loop
Jump statements
• Break statement
• Continue statement
Exploring Popup boxes
It is a window that displays message along with ok button ,cancel
button and in addition it also prompt user to enter some text.
• The alert box
• The Confirm box
• The Prompt Box
The alert box
• It is used to display an alert message and also to display error message after we
validate a form.
• Alert box has OK button which the user has to click to continue with execution.
invoking Function :
function_name(parameters……)
event Description
onsubmit Triggers on submitting form
onselect Triggers on selecting an element
oninvalid Triggers when an element is invalid
oninput Triggers when input is provided for an element
onforminput Triggers when input is provided on a form
onformchange Triggers when a form changes
onfocus Triggers when a window gets focus
oncontextmenu Triggers when context menu is used
onchange Triggers when an element changes
onblur Triggers when a window loses focus
Keyboard Events
Events Description
onkeydown Triggers on pressing a key
onkeypress Triggers when a key is pressed
onkeyup Triggers on releasing a key
Mouse events
Events Description
onclick tiggers
ondblclick
Arrays in JavaScript
• A JavaScript array has the following characteristics:
1.First, an array can hold values of mixed types. For
example, you can have an array that stores elements
with the types number, string, boolean, and null.
2.Second, the size of an array is dynamic and auto-
growing. In other words, you don’t need to specify the
array size up front.
Creating JavaScript arrays
• JavaScript provides you with two ways to create an array. The first one
Is to use the Array constructor as follows:
let scores = new Array();
let scores = Array(10);
To create an array and initialize it with some elements, you pass the
elements as a comma-separated list into the Array() constructor.
let scores = new Array(9,10,8,7,6);
let colors = ['red', 'green', 'blue'];
• To access an element in an array, you specify an index in the square
brackets []
let mountains = ['Everest', 'Fuji', 'Nanga Parbat’];
console.log(mountains[0]);
console.log(mountains[1]);
console.log(mountains[2]);