Академический Документы
Профессиональный Документы
Культура Документы
UNIT-II
Cascading Style Sheet
3.1 Introduction
XHTML style sheets are called cascading style sheets because they can be defined at three different levels
to specify the style of a document. Lower level style sheets can override higher level style sheets, so the
style of the content of a tag is determined, in effect, through a cascade of style-sheet applications.
Levels of Style Sheets
The three levels of style sheets, in order from lowest level to highest level, are inline, document level,
and external.
o Inline style sheets apply to the content of a single XHTML element.
o Document-level style sheets apply to the whole body of a document.
o External style sheets can apply to the bodies of any number of documents.
Inline style sheets have precedence over document style sheets, which have precedence over external
style sheets.
Inline style specifications appear within the opening tag and apply only to the content of that tag.
Document-level style specifications appear in the document head section and apply to the entire body of
the document.
External style sheets stored separately and are referenced in all documents that use them.
External style sheets are written as text files with the MIME type text/css.
They can be stored on any computer on the Web. The browser fetches external style sheets just as it
fetches documents.
The <link> tag is used to specify external style sheets. Within <link>, the rel attribute is used to specify
the relationship of the linked-to document to the document in which the link appears. The href attribute
of <link> is used to specify the URL of the style sheet document.
1. Inline CSS.
2. Internal CSS.
3. External CSS
Inline CSS
For Inline CSS every style content is in HTML elements. It is used for a limited section. Whenever our
requirements are very small we can use inline CSS.
It will affect only single elements. In HTML we require that various HTML tag's views are different so
then we use inline Cascading Style Sheets. There are disadvantage of inline Cascading Style Sheets. It must
be specified on every HTML tag. There is very much time consumed by that and it is not the best practice
for a good programmer and the code will be quite large and very complex.
Inline CSS examples are given below:
Internal CSS
In internal CSS the style of CSS is specified in the <head> section. This is internal CSS, it affects all the
elements in the body section. Internal CSS is used in the condition when we want a style to be used in the
complete HTML body. For that we can use style in the head tag.
External CSS
In External CSS we create a .css file and use it in our HTML page as per our requirements. Generally
external Cascading Style Sheets are used whenever we have many of HTML attributes and we can use
them as required; there is no need to rewrite the CSS style again and again in a complete body of HTML
that inherits the property of the CSS file. There are two ways to create a CSS file. The first is to write the
CSS code in Notepad and save it as a .css file, the second one is to directly add the style sheet in our
HTML page.
property_n: value_n;"
Document style specifications appear as the content of a style element within the header of a document,
although the format of the specification is quite different from that of inline style sheets. The <style> tag
must include the type attribute, set to "text/css (as there are other style sheets in JavaScript).
The list of rules must be placed in a comment, because CSS is not XHTML. Style element must be placed
within the header of a document. Comments in the rule list must have a different form use C comments
(/**/). The general form of the content of a style element is as follows:
Simple selector form is a list of style rules, as in the content of a <style> tag for document-level style
sheets. The selector is a tag name or a list of tag names, separated by commas. Consider the following
examples, in which the property is font-size and the property value is a number of points :
Class Selectors
Used to allow different occurrences of the same tag to use different style specifications. A style class has a
name, which is attached to the tags name with a period.
p.narrow {property-value list}
p.wide {property-value list}
The class you want on a particular occurrence of a tag is specified with the class attribute of the
tag.
Generic Selectors
A generic class can be defined if you want a style to apply to more than one kind of tag.
A generic class must be named, and the name must begin with a period without a tag name in
its name. For Example:
id Selectors
An id selector allow the application of a style to one specific element. The general form of an id
selector is as follows :
#specific-id {property-value list}
Universal Selectors
The universal selector, denoted by an asterisk(*), which applies style to all elements in the
document. For example:
Pseudo Classes
Pseudo classes are styles that apply when something happens, rather than because the target
element simply exists. Names of pseudo classes begin with colons hover classes apply when the
mouse cursor is over the element focus classes apply when an element has focus i.e. the mouse cursor is
over the element and the left mouse button is clicked.
The following will illustrates the use of different sequence value types in nested lists:
3.7 Color
Color Groups:
Three levels of collections of colours might be used by an XHTML document. The smallest useful set of
colours includes only those that have standard names and are guaranteed to be correctly displayable by all
browsers on all color monitors. This collection of 17 colours is called the named colours.
h1.one {
Borders:
Border-style
It can be dotted, dashed, double
Border-top-style
Border-bottom-style
Border-left-style
Border-right-style
Border-width
It can be thin, medium, thick or any length value
Border-top-width
Border-bottom-width
Border-left-width
Border-right-width
Border-color
Border-top-color
Border-bottom-color
Border-left-color
Border-right-color
In the example, notice that the background image is replicated as necessary to fill the area of the element.
This replication is called tiling. Tiling can be controlled with the background-repeat property, which can
take the value repeat (the default), no-repeat, repeat-x, or repeat-y. The no-repeat value specifies that
just one copy of the image is to be displayed. The repeat-x value means that the image is to be repeated
horizontally; repeat-y means that the image is to be repeated vertically. In addition, the position of a non-
repeated background image can be specified with the background-position property, which can take a
large number of different values. The keyword values are top, center, bottom, left, and right, all of which
can be used in many different combinations.