0% found this document useful (0 votes)
41 views

Dynamic Hyper Text Markup Language

This document discusses Dynamic Hypertext Markup Language (DHTML) and how it combines HTML, Cascading Style Sheets (CSS), and scripting languages to create dynamic and interactive web pages. It explains that HTML defines page elements, CSS controls styles and positioning, and scripting languages allow manipulating elements in response to user input. The document also provides examples of CSS syntax, selectors, and how styles can be applied via internal, inline, or external styling.

Uploaded by

Varun Arora
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

Dynamic Hyper Text Markup Language

This document discusses Dynamic Hypertext Markup Language (DHTML) and how it combines HTML, Cascading Style Sheets (CSS), and scripting languages to create dynamic and interactive web pages. It explains that HTML defines page elements, CSS controls styles and positioning, and scripting languages allow manipulating elements in response to user input. The document also provides examples of CSS syntax, selectors, and how styles can be applied via internal, inline, or external styling.

Uploaded by

Varun Arora
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 89

Dynamic Hyper Text Markup Language

Dynamic HTML
DHTML has evolved to meet the increasing demand for eye
catching web sites.

DHTML combines HTML with Cascading Style Sheets (CSS)


and Scripting Languages.

HTML specifies a web page’s elements like table, frame,


paragraph, bulleted list, etc.

Cascading Style sheets can be used to determine an element’s


size, color, position and a number of other features.

Scripting Languages can be used to manipulate the web page’s


element so that style assigned to them can change in response to
a user’s input.
What is CSS?
• CSS stands for Cascading Style Sheets
• It is a simple design language intended to simplify the process of
making web pages presentable.
• CSS handles the look and feel part of a web page.
• Styles define how to display HTML elements
• Using CSS, you can control the color of the text, the style of
fonts, the spacing between paragraphs, how columns are sized and
laid out, what background images or colors are used, as well as a
variety of other effects.
• Styles are normally stored in Style Sheets
• External Style Sheets can save you a lot of work
• External Style Sheets are stored in CSS files
• Multiple style definitions will cascade into one
• Most commonly, CSS is combined with the markup languages
HTML or XHTML.
Advantages of CSS

CSS saves time - You can write CSS once and then reuse
the same sheet in multiple HTML pages. You can define a
style for each HTML element and apply it to as many web
pages as you want.

Pages load faster - If you are using CSS, you do not need
to write HTML tag attributes every time. Just write one
CSS rule of a tag and apply it to all the occurrences of that
tag. So, less code means faster download times.
Advantages of CSS(contd..)

Easy maintenance - To make a global change, simply change the


style, and all the elements in all the web pages will be updated
automatically.

Superior styles to HTML - CSS has a much wider array of attributes


than HTML, so you can give a far better look to your HTML page in
comparison to HTML attributes.

Multiple Device Compatibility - Style sheets allow content to be


optimized for more than one type of device. By using the same
HTML document, different versions of a website can be presented for
handheld devices such as PDAs and cellphones or for printing.
Advantages of CSS(contd..)

Global web standards – Now HTML attributes are being


deprecated and it is being recommended to use CSS. So
it’s a good idea to start using CSS in all the HTML pages
to make them compatible with future browsers.
CSS SYNTAX

A CSS comprises of style rules that are interpreted by the browser and then applied to
the corresponding elements in your document.
 The Style assignment process is accomplished with the <STYLE>….</STYLE> tags.
 Between the <STYLE>….</STYLE> tags, specific style attribute are listed.
 The <STYLE>….</STYLE> tags are written within the <HEAD>…</HEAD>
TAGS.
 A style rule is made of three parts:
 Selector: A selector is an HTML tag at which a style will be applied. This could be
any tag like <h1> or <table> etc.
 Property: A property is a type of attribute of HTML tag. Put simply, all the HTML
attributes are converted into CSS properties. They could be color, border, etc.
 Value: Values are assigned to properties. For example, color property can have the
value either red or #F1F1F1 etc.
You can put CSS Style Rule Syntax as follows:
selector { property: value }
EXAMPLE
<STYLE Type = “text/css”>
Tag{attribute:value;attribute:value;}
</STYLE>
Ways to define selectors

We define selectors in various simple ways based on


our comfort.
 The Type Selectors
Here we can specify the tag .
example to give a color to all level 1 headings:
h1 {
color: #36CFFF;
}
The Universal Selectors
Rather than selecting elements of a specific type, the
universal selector quite simply matches the name of
any element type:
*{
color: #000000;
}
This rule renders the content of every element in our
document in black.
The Descendant Selectors
Suppose you want to apply a style rule to a particular
element only when it lies inside a particular element.
As given in the following example, the style rule will
apply to <em> element only when it lies inside the
<ul> tag.
ul em {
color: #000000;
}
The Class Selectors

You can define style rules based on the class attribute of the elements. All the elements
having that class will be formatted according to the defined rule.
.black {
color: #000000;
}
This rule renders the content in black for every element with class attribute set to black in
our document. You can make it a bit more particular. For example:
h1.black {
color: #000000;
}
This rule renders the content in black for only <h1> elements with class attribute set to black.
You can apply more than one class selectors to a given element. Consider the following
example:
<p class="center bold">
This para will be styled by the classes center and bold.
</p>
The ID Selectors

You can define style rules based on the id attribute of the elements. All the
elements having that id will be formatted according to the defined rule.
#black {
color: #000000;
}
This rule renders the content in black for every element with id attribute set
to black in our document. You can make it a bit more particular. For
example:
h1#black {
color: #000000;
}
This rule renders the content in black for only <h1> elements with id
attribute set to black.
.
The Child Selectors

You have seen the descendant selectors. There is one


more type of selector, which is very similar to
descendants but have different functionality. Consider
the following example:
body > p {
color: #000000;
}
This rule will render all the paragraphs in black if they
are a direct child of the <body> element. Other
paragraphs put inside other elements like <div> or <td>
would not have any effect of this rule.
The Attribute Selectors

You can also apply styles to HTML elements with


particular attributes. The style rule below will match
all the input elements having a type attribute with a
value of text:
input[type="text"]{
color: #000000;
}
The advantage to this method is that the <input
type="submit" /> element is unaffected, and the
color applied only to the desired text fields.
Multiple Style Rules

You may need to define multiple style rules for a single element. You can
define these rules to combine multiple properties and corresponding
values into a single block as defined in the following example:
h1 {
color: #36C;
font-weight: normal;
letter-spacing: .4em;
margin-bottom: 1em;
text-transform: lowercase;
}
Here all the property and value pairs are separated by a semicolon (;).
You can keep them in a single line or multiple lines. For better
readability, we keep them in separate lines.
Grouping Selectors

You can apply a style to many selectors if you like. Just separate the selectors with a comma, as given
in the following example:
h1, h2, h3 {
color: #36C;
font-weight: normal;
letter-spacing: .4em;
margin-bottom: 1em;
text-transform: lowercase;
}
This define style rule will be applicable to h1, h2 and h3 element as well. The order of the list is
irrelevant. All the elements in the selector will have the corresponding declarations applied to them.
You can combine the various class selectors together as shown below:
#content, #footer, #supplement {
position: absolute;
left: 510px;
width: 200px;
}
Inclusion

There are three ways to associate styles with your HTML document.
Embedded CSS -The <style> Element
You can put your CSS rules into an HTML document using the
<style> element. This tag is placed inside the <head>...</head>
tags. Rules defined using this syntax will be applied to all the
elements available in the document. Here is the generic syntax:
<head>
<style type="text/css“ >
Style Rules
............
</style>
</head>
Attributes of <style>

Attributes associated with <style> elements are:

Attributes Value Description


type Text/css Specifies the style sheet
language as a content
type. This is a required
attribute
media Screen Specifies the device, the
tv document will be
projection displayed on. Default
handheld value is all. This is an
optional attribute.
Example

<head>
<style type="text/css" media="all">
h1{
color: #36C;
}
</style>
</head>
Inline CSS -ThestyleAttribute

You can use style attribute of any HTML element to


define style rules. These rules will be applied to that
element only.
Here is the generic syntax:
<element style="...style rules....">
Attributes:

Attribute Value Description


Style Style Rules The value of the style
attribute is a
combination of style
declarations seperated
by semicolon(;)
Example

Following is the example of inline CSS based on the


above syntax:
<h1 style ="color:#36C;"> This is inline CSS </h1>
External CSS -The <link> Element

The <link> element can be used to include an external


stylesheet file in your HTML document.
An external style sheet is a separate text file with .css
extension. You define all the Style rules within
this text file and then you can include this file in
any HTML document using <link> element.
Here is the generic syntax of including external CSS file:
<head>
<link rel=“stylesheet” type="text/css" href="..."
media="..." />
</head>
Attributes

Attributes associated with <link> elements are:


al attribute.

Attribute Value Description


type Text/css Specifies the style sheet language as a content-
type (MIME type). This attribute is required.

href URL Specifies the style sheet file having Style rules.
This attribute is a required.
media Screen Specifies the device the document will be
tv displayed on. Default value is all. This is an
projection option
handheld
Print
all
Example

Consider a simple style sheet file with a name mystyle.css having the
following rules:
h1, h2, h3 {
color: #36C;
font-weight: normal;
letter-spacing: .4em;
margin-bottom: 1em;
text-transform: lowercase;
}
Now you can include this file mystyle.css in any HTML document as follows:
<head>
<link rel=“stylesheet” type="text/css" href="mystyle.css" media="all" />
</head>
CSS Rules Overriding

We have discussed three ways to include style sheet rules


in an HTML document. Here is the rule to override any
Style Sheet Rule.
Any inline style sheet takes the highest priority. So, it will
override any rule defined in <style>...</style> tags or the
rules defined in any external style sheet file.
Any rule defined in <style>...</style> tags will override
the rules defined in any external style sheet file.
Any rule defined in the external style sheet file takes the
lowest priority, and the rules defined in this file will be
applied only when the above two rules are not applicable.
CSS Comments

Many times, you may need to put additional comments in your style sheet blocks.
So, it is very easy to comment any part in the style sheet. You can simply put your
comments inside /*.....this is a comment in style sheet.....*/.
You can use /* ....*/ to comment multi-line blocks in similar way you do in C and C+
+ programming languages.
Example
/* This is an external style sheet file */
h1, h2, h3 {
color: #36C;
font-weight: normal;
letter-spacing: .4em;
margin-bottom: 1em;
text-transform: lowercase;
}
/* end of style rules. */
MEASUREMENT UNITS

CSS supports a number of measurements including


absolute units such as inches, centimeters, points,
and so on, as well as relative measures such as
percentages and em units. You need these values
while specifying various measurements in your Style
rules e.g. border="1px solid red".
Colors

CSS uses color values to specify a color. Typically,


these are used to set a color either for the foreground
of an element (i.e., its text) or for the background of
the element. They can also be used to affect the color
of borders and other decorative effects.
List of All Possible Formats
Background

We can set the following background properties of an element:


The background-color property is used to set the
background color of an element.
The background-image property is used to set the
background image of an element.
The background-repeat property is used to control the
repetition of an image in the background.
The background-position property is used to control
the position of an image in the background
The background property is used as a shorthand to
specify a number of other background properties.
Color and Background Attributes
Attributes Values
color A color name or color code.
(Sets an element’s text-color.)
Background-color Sets the background color.
Background-image Sets the background image
Background-repeat With a background image specified, sets
up how the image repeats throughout
the page, repeat-x (repeats horizontally),
repeat-y(repeats vertically), repeat(both),
no-repeat
Set the Background Color

Example:
<p style="background-color:yellow;">
This text has a yellow background color.
</p>
Set the Background Image

<table style="background-
image:url(/images/pattern1.gif);">
<tr><td>
This table has background image set.
</td></tr>
</table>
Repeat the Background Image
The following example demonstrates how to repeat the background image if an image is small.
You can use no-repeat value for the background-repeat property if you don't want to repeat an image. In this case, the image will display only
once.
By default, the background-repeat property will have a repeat value.
<table style="background-image:url(/images/pattern1.gif);
background-repeat: repeat;">
<tr><td>
This table has background image which repeats multiple times.
</td></tr>
</table>
The following example which demonstrates how to repeat the background image vertically.
<table style="background-image:url(/images/pattern1.gif);
background-repeat: repeat-y;">
<tr><td>
This table has background image set which will repeat vertically.
</td></tr>
</table>

The following example demonstrates how to repeat the background image horizontally.
<table style="background-image:url(/images/pattern1.gif);
background-repeat: repeat-x;">
<tr><td>
This table has background image set which will repeat horizontally.
</td></tr>
</table>
Set the Background Image Position

The following example demonstrates how to set the background image position 100 pixels away
from the left side.
<table style="background-image:url(/images/pattern1.gif);
background-position:100px;">
<tr><td>
Background image positioned 100 pixels away from the left.
</td></tr>
</table>
The following example demonstrates how to set the background image position 100 pixels away
from the left side and 200 pixels down from the top.
<table style="background-image:url(/images/pattern1.gif); background-position:100px 200px;">
<tr><td>
This table has background image positioned 100
pixels away from the left and 200 pixels from the top.
</td></tr>
</table
Fonts

We can set the following font properties of an element:


The font-family property is used to change the
face of a font.
The font-style property is used to make a font
italic or oblique.
The font-weight property is used to increase or
decrease how bold or light a font appears.
The font-size property is used to increase or
decrease the size of a font.
The font property is used as shorthand to specify a
number of other font properties.
Font Attributes
Attributes Values
Font-family A comma-delimited sequence of font
family names (serif, sans-serif, cursive)
Note: if the browser support the first font , it tries the next one.

Font-style Normal, italic or oblique

Font-weight Normal, bold, bolder, lighter

Font-size A term that denotes absolute size(xx-


small, x-small, small, medium, large, x-
large, xx-large)
Font Attributes
<HTML>
<HEAD>
<STYLE Type = "text/css">
H1 {font-family:arial, helvetica}
P {font-size:12pt; font-style:italic}
</STYLE>
</HEAD>
<BODY>
<H1> Silicon Chip Technologies </H1>
<P> Silicon Chip Technologies, a private limited company,
was founded in December 1989.

<P>
The vision of this company is to provide any corporate client a
single entity which address all their Software Development,
Technical and User Documentation, Training and Manpower
Recruitment needs.
</BODY>
</HTML>
Set the Font Family

Following is the example, which demonstrates how


to set the font family of an element. Possible value
could be any font family name.
<p style="font-family: georgia, garamond,serif;">
This text is rendered in either georgia, garamond, or
the default
serif font depending on which font you have at your
system.
</p>
Set the Font Style

The following example demonstrates how to set the


font style of an element. Possible values are normal,
italic and oblique.
<p style="font-style: italic;">
Set the Font Weight

The following example demonstrates how to set the font weight of an


element. The font-weight property provides the functionality to specify
how bold a font is. Possible values could be normal, bold, bolder,
lighter, 100, 200, 300, 400, 500, 600, 700, 800, 900.
<p style="font-weight:bold;">
This font is bold.
</p>
<p style="font-weight:bolder;">
This font is bolder.
</p>
<p style="font-weight:900;">
This font is 900 weight.
</p>
Set the Font Size

The following example demonstrates how to set the font size of an


element. The font-size property is used to control the size of fonts.
Possible values could be xx-small, x-small, small, medium, large, x-
large, xx-large, smaller, larger, size in pixels or in %.
<p style="font-size:20px;">
This font size is 20 pixels
</p>
<p style="font-size:small;">
This font size is small
</p>
<p style="font-size:large;">
This font size is large
</p>
Text

We can set the following text properties of an element:


The color property is used to set the color of a text.
The direction property is used to set the text direction.
The letter-spacing property is used to add or subtract space
between the letters that make up a word.
The word-spacing property is used to add or subtract space
between the words of a sentence.
The text-indent property is used to indent the text of a
paragraph.
The text-align property is used to align the text of a document.
The text-decoration property is used to underline, overline, and
strikethrough text(line-through).
The text-transform property is used to capitalize text or convert
text to uppercase or lowercase letters.
Text Attributes
Attributes Values
Text-decoration Adds decoration to an elements text. None, underline,
overline, line-through.

Text-transform Applies a transformation to the text capitalize (puts the


text into initial caps),uppercase, lowercase or none

Text-align Aligns text within an element. Left, right, center, or


justify

Text-indent Indents the first line of text. A percentage of the


element’s width or a length
Set the text color

The following example demonstrates how to set the


text color. Possible value could be any color name in
any valid format.
<p style="color:red;">
This text will be written in red.
</p>
Set the direction of the text

The following example demonstrates how to set the


direction of a text. Possible values are ltr or rtl.
<p style="direction:rtl;">
This text will be renedered from right to left
</p>
Set the Space between Characters

The following example demonstrates how to set the


space between characters. Possible values are
normal or a number specifying space.
<p style="letter-spacing:5px;">
This text is having space between letters.
</p>
Set the Space between Words

The following example demonstrates how to set the


space between words. Possible values are normal or
a number specifying space.
<p style="word-spacing:5px;">
This text is having space between words.
</p>
Set the Text Indent

The following example demonstrates how to indent


the first line of a paragraph. Possible values are % or
a number specifying indent space.
<p style="text-indent:1cm;">
This text will have first line indented by 1cm
and this line will remain at its actual position
this is done by CSS text-indent property.
</p>
Set the Text Alignment

The following example demonstrates how to align a text.


Possible values are left, right, center, justify.
<p style="text-align:right;">
This will be right aligned.
</p>
<p style="text-align:center;">
This will be center aligned.
</p>
<p style="text-align:left;">
This will be left aligned.
</p>
Decorating the Text

The following example demonstrates how to decorate a text. Possible values


are none, underline, overline, line-through, blink.
<p style="text-decoration:underline;">
This will be underlined
</p>
<p style="text-decoration:line-through;">
This will be striked through.
</p>
<p style="text-decoration:overline;">
This will have a over line.
</p>
<p style="text-decoration:blink;">
This text will have blinking effect
</p>
Set the Text Cases

The following example demonstrates how to set the cases for a


text. Possible values are none, capitalize, uppercase, lowercase.
<p style="text-transform:capitalize;">
This will be capitalized
</p>
<p style="text-transform:uppercase;">
This will be in uppercase
</p>
<p style="text-transform:lowercase;">
This will be in lowercase
</p>
Images

Images play an important role in any webpage. Though it is not


recommended to include a lot of images, but it is still important
to use good images wherever required.
CSS plays a good role to control image display. You can set the
following image properties using CSS.
The border property is used to set the width of an image
border.
The height property is used to set the height of an image.
The width property is used to set the width of an image.
The -moz-opacity property is used to set the opacity of
an image.
The Image Border Property

The border property of an image is used to set the


width of an image border. This property can have a
value in length or in %.
A width of zero pixels means no border.
Here is an example:
<img style="border:0px;" src="/images/css.gif" />
<br />
<img style="border:3px dashed red;"
src="/images/css.gif" />
The Image Height Property

The height property of an image is used to set the


height of an image. This property can have a value in
length or in %. While giving value in %, it applies it in
respect of the box in which an image is available.
Here is an example:
<img style="border:1px solid red; height:100px;"
src="/images/css.gif" />
<br />
<img style="border:1px solid red; height:50%;"
src="/images/css.gif" />
The Image Width Property

The width property of an image is used to set the


width of an image. This property can have a value in
length or in %. While giving value in %, it applies it in
respect of the box in which an image is available.
Here is an example:
<img style="border:1px solid red; width:100px;"
src="/images/css.gif" />
<br />
<img style="border:1px solid red; width:100%;"
src="/images/css.gif" />
LINKS

You can set the following properties of a hyperlink:


The :link signifies unvisited hyperlinks.
The :visited signifies visited hyperlinks.
The :hover signifies an element that currently has the user's mouse pointer
hovering over it.
The :active signifies an element on which the user is currently clicking.

Usually, all these properties are kept in the header part of the HTML document.
Remember a:hover MUST come after a:link and a:visited in the CSS definition in order to
be effective. Also, a:active MUST come after a:hover in the CSS definition as follows:
<style type="text/css">
a:link {color: #000000}
a:visited {color: #006600}
a:hover {color: #FFCC00}
a:active {color: #FF00CC}
</style>
TABLES

You can set the following properties of a table:


The border-collapse specifies whether the browser should control the
appearance of the adjacent borders that touch each other or whether
each cell should maintain its style.
The border-spacing specifies the width that should appear between
table cells.
The caption-side captions are presented in the <caption> element. By
default, these are rendered above the table in the document. You use
the caption-side property to control the placement of the table
caption.
The empty-cells specifies whether the border should be shown if a cell
is empty.
The table-layout allows browsers to speed up the layout of a table by
using the first width properties it comes across for the rest of a
column rather than having to load the whole table before rendering it.
The border-collapse Property

This property can have two values collapse and separate.


The following example uses both the values:
<style type="text/css">
table.one {border-collapse:collapse;}
table.two {border-collapse:separate;}
td.a {
border-style:dotted;
border-width:3px;
border-color:#000000;
padding: 10px;
}
td.b {border-style:solid;
border-width:3px;
border-color:#333333;
padding:10px;
}
</style>
<table class="one">
<caption>Collapse Border Example</caption>
<tr><td class="a"> Cell A Collapse Example</td></tr>
<tr><td class="b"> Cell B Collapse Example</td></tr>
</table>
<br />
<table class="two">
<caption>Separate Border Example</caption>
<tr><td class="a"> Cell A Separate Example</td></tr>
<tr><td class="b"> Cell B Separate Example</td></tr>
</table>
The border-spacing Property

The border-spacing property specifies the distance that separates the


adjacent cells’ borders. It can take either one or two values; these should be
units of length.
If you provide one value, it applies to both vertical and horizontal borders.
Or you can specify two values, in which case, the first refers to the
horizontal spacing and the second to the vertical spacing:
NOTE: Unfortunately, this property does not work in Netscape 7
or IE 6.
<style type="text/css">
/* If you provide one value */
table.example {border-spacing:10px;}
/* This is how you can provide two values */
table.example {border-spacing:10px; 15px;}
</style>
Caption-Side Property

The caption-side property allows you to specify


where the content of a <caption> element should be
placed in relationship to the table. The table that
follows lists the possible values.
This property can have one of the four values top,
bottom, left, or right. The following example uses
each value.
NOTE: These properties may not work with
your IE Browser.
The empty-cells Property

The empty-cells property indicates whether a cell


without any content should have a border displayed.
This property can have one of the three values -
show, hide.
Here is the empty-cells property used to hide
borders of empty cells in the <table> element.
BORDERS

The border properties allow you to specify how the


border of the box representing an element should look.
There are three properties of a border you can change:
The border-color specifies the color of a border.
The border-style specifies whether a border
should be solid, dashed line, double line, or one
of the other possible values.
The border-width specifies the width of a
border.
Border Attributes
Attributes Values
Border-style Solid, double, groove, inset, outset
Border-color A color name or color code
Border-width Thin, medium, length
Border-top-width Thin, medium, length
Border-bottom-width Thin, medium, length
Border-left-width Thin, medium, length
Border-top Specifies width, color and style
Border-bottom Specifies width, color and style
Border-left Specifies width, color and style
Border-right Specifies width, color and style
border Sets all properties at once
Border-right-width Thin, medium, think or length
The border-color Property

The border-color property allows you to change the color


of the border surrounding an element.
You can individually change the color of the bottom, left, top
and right sides of an element's border using the
properties:
border-bottom-color changes the color of bottom
border.
border-top-color changes the color of top border.
border-left-color changes the color of left border.
border-right-color changes the color of right
border.
The border-style Property

The border-style property allows you to select one of the following


styles of border:
none: No border. (Equivalent of border-width:0;)
solid: Border is a single solid line.
dotted: Border is a series of dots.
dashed: Border is a series of short lines.
double: Border is two solid lines.
groove: Border looks as though it is carved into the page.
ridge: Border looks the opposite of groove.
inset: Border makes the box look like it is embedded in the
page.
outset: Border makes the box look like it is coming out of
the canvas.
The border-width Property

The border-width property allows you to set the width of an


element borders. The value of this property could be either a
length in px, pt, or cm, or it should be set to thin, medium, or
thick.
You can individually change the width of the bottom, top, left,
and right borders of an element using the following properties:
border-bottom-width changes the width of bottom
border.
border-top-width changes the width of top border.
border-left-width changes the width of left border.
border-right-width changes the width of right border.
Border-Shorthand Property

The border property allows you to specify color,


style, and width of lines in one property:
The following example shows how to use all the three
properties into a single property. This is the most
frequently used property to set border around any
element.
<p style="border:4px solid red;">
This example is showing shorthand property for
border.
</p>
MARGINS

The margin property defines the space around an HTML element. It is


possible to use negative values to overlap content.
The values of the margin property are not inherited by the child elements.
Remember that the adjacent vertical margins (top and bottom margins) will
collapse into each other so that the distance between the blocks is not the
sum of the margins, but only the greater of the two margins or the same size
as one margin if both are equal.
We have the following properties to set an element margin.
The margin specifies a shorthand property for setting the margin
properties in one declaration.
The margin-bottom specifies the bottom margin of an element.
The margin-top specifies the top margin of an element.
The margin-left specifies the left margin of an element.
The margin-right specifies the right margin of an element.
LISTS

We have the following five CSS properties, which can be used to
control lists:
The list-style-type allows you to control the shape or
appearance of the marker.
The list-style-position specifies whether a long point
that wraps to a second line should align with the first
line or start underneath the start of the marker.
The list-style-image specifies an image for the marker
rather than a bullet point or number.
The list-style serves as shorthand for the preceding
properties.
The list-style-type Property

The list-style-type property allows you to control


the shape or style of a bullet point (also known as a
marker) in case of unordered lists and the style of
numbering characters in ordered lists.
Here are the values, which can be used for an
unordered list:

Value Description
disc A filled-in Circle
Circle An Empty Circle
square A Solid Square
values for an ordered list
Value Description Example
Decimal Number 1,2,3,4
Decimal-leading- 0 before the number 01,02,03
Zero
Lower-alpha Lowercase alphanumeric a,b,c,d
characters
Upper-alpha Uppercase alphanumeric A,B,C,D
characters
Lower-Roman Lowercase Roman Numerals i,ii,iii,iv
Upper-Roman Uppercase Roman Numerals I,II,III,IV
Lower-greek The marker is lower greek Alpha,beta,gamma
The list-style-position Property

The list-style-position property indicates whether the


marker should appear inside or outside of the box
containing the bullet points. It can have one of the two
values:
Value Description
inside If the text goes onto a second line, the text will
wrap underneath the marker. It will also appear
indented to where the text would have started if the list
had a value of outside.
outside If the text goes onto a second line, the text will
be aligned with the start of the first line (to the right of
the bullet).
The list-style-image Property

The list-style-image allows you to specify an image so that you can use your
own bullet style. The syntax is similar to the background-image property with
the letters url starting the value of the property followed by the URL in
brackets. If it does not find the given image then default bullets are used.
Here is an example:
<ul>
<li style="list-style-image: url(/images/bullet.gif);">Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ul>
<ol>
<li style="list-style-image: url(/images/bullet.gif);">Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ol>
PADDINGS

The padding property allows you to specify how much space should
appear between the content of an element and its border:
The value of this attribute should be either a length, a percentage, or
the word inherit. If the value is inherit, it will have the same padding
as its parent element. If a percentage is used, the percentage is of the
containing box.
The padding-bottom specifies the bottom padding of an
element.
The padding-top specifies the top padding of an element.
 The padding-left specifies the left padding of an element.
The padding-right specifies the right padding of an element.
The padding serves as shorthand for the preceding
properties.
CURSORS

The cursor property of CSS allows you to specify the


type of cursor that should be displayed to the user.
One good usage of this property is in using images
for submit buttons on forms. By default, when a
cursor hovers over a link, the cursor changes from a
pointer to a hand. However, it does not change form
for a submit button on a form. Therefore, whenever
someone hovers over an image that is a submit
button, it provides a visual clue that the image is
clickable.
values for the cursor property

Value Description
auto Shape of the cursor depends on the context area it is over. For example,
an ‘I’ over text, a ‘hand’ over a link, and so on.
crosshair A crosshair or plus sign.
default An arrow.
pointer A pointing hand (in IE 4 this value is hand).
move The ‘I’ bar.
e-resize The cursor indicates that an edge of a box is to be moved right (east).

ne-resize The cursor indicates that an edge of a box is to be moved up and


right (north/east).
nw-resize The cursor indicates that an edge of a box is to be moved up and
left (north/west).
n-resize The cursor indicates that an edge of a box is to be moved up (north).
Value Description
se-resize The cursor indicates that an edge of a box is to be
moved down and right (south/east).
sw-resize The cursor indicates that an edge of a box is to be
moved down and left (south/west).
s-resize The cursor indicates that an edge of a box is to be
moved down (south).
w-resize The cursor indicates that an edge of a box is to be
moved left (west).
text The I bar.
wait An hour glass.
help A question mark or balloon, ideal for use over help
buttons.
Example

<p>Move the mouse over the words to see the cursor change:</p>
<div style="cursor:auto">Auto</div>
<div style="cursor:crosshair">Crosshair</div>
<div style="cursor:default">Default</div>
<div style="cursor:pointer">Pointer</div>
<div style="cursor:move">Move</div>
<div style="cursor:e-resize">e-resize</div>
<div style="cursor:ne-resize">ne-resize</div>
<div style="cursor:nw-resize">nw-resize</div>
<div style="cursor:n-resize">n-resize</div>
<div style="cursor:se-resize">se-resize</div>
<div style="cursor:sw-resize">sw-resize</div>
<div style="cursor:s-resize">s-resize</div>
<div style="cursor:w-resize">w-resize</div>
<div style="cursor:text">text</div>
<div style="cursor:wait">wait</div>
<div style="cursor:help">help</div>
POSITIONING

CSS helps you to position your HTML element. You can put any HTML element at whatever location you like.
 You can specify whether you want the element positioned relative to its natural position in the page or
absolute based on its parent element.
Relative Positioning
Relative positioning changes the position of the HTML element relative to where it normally appears. So
"left:20" adds 20 pixels to the element's LEFT position.
You can use two values top and left along with the position property to move an HTML element anywhere in
an HTML document.
Move Left - Use a negative value for left.
Move Right - Use a positive value for left.
Move Up - Use a negative value for top.
Move Down - Use a positive value for top.

NOTE: You can use the bottom or right values as well in the same way as top and left.
Here is an example:
<div style="position:relative;left:80px;top:2px; background-color:yellow;">
This div has relative positioning.
</div>
Absolute Positioning

An element with position: absolute is positioned at the specified coordinates


relative to your screen top-left corner.
You can use two values top and left along with the position property to move an HTML
element anywhere in HTML document.
Move Left - Use a negative value for left.
Move Right - Use a positive value for left.
Move Up - Use a negative value for top.
Move Down - Use a positive value for top.

NOTE: You can use bottom or right values as well in the same way as top
and left.
Here is an example:
<div style="position:absolute;left:80px;top:20px;
background-color:yellow;">
This div has absolute positioning.
</div>
Layers

CSS gives you an opportunity to create layers of various


divisions. The CSS layers refer to applying the z-index
property to elements that overlap with each other.
The z-index property is used along with the position
property to create an effect of layers. You can specify
which element should come on top and which element
should come at bottom.
A z-index property can help you to create more
complex webpage layouts. The following example
shows how to create layers in CSS.
Example

<div style="background-color:red;
width:300px;
height:100px;
position:relative;
top:10px;
left:80px;
z-index:2">
</div>
<div style="background-color:yellow;
width:300px;
height:100px;
position:relative;
top:-60px;
left:35px;
z-index:1;">
</div>
Using the <SPAN>…</SPAN> Tag
SPAN is an HTML element that play a prominent role in
style sheets.

In the body of the document, <SPAN>…</SPAN> is used to


set the boundaries of the rule’s styling specifications.

You might also like