Professional Documents
Culture Documents
Understanding styles:
A style is a formatting rule. That rule can be applied to an individual tag, to all instances of a certain
tag within a document or to all instances of a certain tag across a group of documents.
To use a square bullet character in an unordered list use the style = argument with the <ul> tag like
this:
<ul style = “list-style-type: square”>
We can create a <style> section within the <head> section that creates a global style rule for all <ul>
tags in the document. The <style> section might look like this:
To specify that the heading text must be both red and 14 pixels in height.
Ex: <style> h1
{
color : red;
font-size :14px;
}
</style>
If all heading styles <h1> through <h6> should be red:
Ex: <style> h1, h2, h3, h4, h5, h6
{
color : red;
font-size :14px;
}
</style>
Creating styles for nested tags:
Instead of using a single style name at the beginning of the rule, specify that the item is nested by
listing the parent style name followed by the descendent style name to use round bullets for all bulleted lists
that are nested within numbered lists:
Ex: ol ul { list-style-type : circle }
Multiple nested levels are
Ex: ol ul ul { list-style-type : circle }
To make all the bold text that appear in blue.
Ex: ul b { color : blue }
2
<li id = “special”> Fruits </li>
Then define the ID in the <style> area, preceding the ID name with a hash symbol (#) like this:
Ex: <style>
#special {
color : red
}
</style>
PSEUDO CLASS
Applying styles to hyperlinks:
By default in most browsers, textual hyperlinks appear as underlined blue text and visited hyper links
appear as underlined purple text.
Hyperlink formatting can be controlled by placing arguments in the <a>tag for each link
<a href=”ex.htm” style= “color: magenta”> </a>
To apply different colors use pseudo classes. A pseudo class is a class that uses a variable to
determine membership. HTML defines pseudo classes called link and visited, for unvisited and visited
hyperlinks. It makes all visited links magenta and all unvisited links black.
Ex: <Style>
a: link { color: black }
a: visited { color: magenta }
</style>
3
The current version of html (4.01) supports cascading style sheets. web designer use cascading style sheets
to specify a formatting for particular tag type-usually in a separate style sheet document-and then apply that
style sheets to multiple pages.
CSS Syntax
A CSS rule has two main parts: a selector, and one or more declarations:
Style sheet
<html>
4
<head>
<style type="text/css">
body
{
background-color:skyblue;
}
h1
{
color:orange;
text-align:center;
}
p
{
font-family:"Times New Roman";
font-size:20px;
}
</style>
</head>
<body>
<h1>CSS example!</h1>
<p>This is a paragraph.</p>
</body>
</html>
OUTPUT:
CREATING
CLASSES AND
IDS FOR
APPLYING
STYLES:
Classes and ids mark certain elements so you can refewr to them in your style sheet. A class can be
applied to multiple selections , whereas an id uniquely identifies a specific selection within a document.
For example:
5
Suppose you have an unordered list opr product and you want to new products to appear in red. One
way to do it would be manually add the style=”color: red” argument to each of these items like this:
<li style=”color: red”>spraying techniques for fruit trees</li>
however this method is not optimal because if you change your mind and decide to make the new items blue
instead, you would need to make the change manually for each instances. A better way to create a class
called new and defines formatting for within the <style>area. Then you could apply the new class to each
bulletin point you want to spot light.
To create a class ,add a class=argument to the opening tag for the element. for example
<li class=”new”>spraying techniques for fruit trees</li>
then in the <style> area add a style in that defines in the class as red.
<style>
new
{
color: red
}
</style>
ids work the same way, except you can apply them only once per document. For example, you might apply
an id to a unique heading. To create an id, add an id=argument to the tag, like this:
<li id=”special “>spraying techniques </li>
then define the id in the <style>area.
Example:
<style>
#special
{
color: red
}
</style>
Font Family
The font family of a text is set with the font-family property.
The font-family property should hold several font names as a "fallback" system. If the browser does not
support the first font, it tries the next font.
Start with the font you want, and end with a generic family, to let the browser pick a similar font in the
generic family, if no other fonts are available.
Create an embedded style sheet governing the appearance of horizontal lines:
6
OPEN the index file in Notepad and in Internet Explorer.
7
FORMATTING PARAGRAPHS BY USING STYLESHEET:
Apply different bullet characters to a nested list by creating styles in the <style> area of a document:
1. Mxamine the index file in Internet Explorer. That the first-level bullet characters are discs, the
Second-level bullet characters are circles, and the third-level bullet characters are squares.
2. In Notepad, in the <style> section, create a style rule specifying that first-level unordered
lists have a square bullet character:
<style>
hr {color: green; background-color: green; height: 3px;}ul {list-style-type: square}
</style>
3 Create a style rule specifying that second-level unordered lists have a disc bullet character:
<style>
hr {color: green; background-color: green; height: 3px;}ul {list-style-type: square}ul ul
{list-style-type: disc}
</style>
4 Create a style rule specifying that third-level unordered lists have a circle bullet character:
<style>
hr {color: green; background-color: green; height: 3px;}
ul {list-style-type: square}ul ul {list-style-type: disc}ul ul ul {list-style-type: circle}
</style>
8
CLOSE the Notepad and Internet Explorer windows.
Classes and IDs mark certain elements so you can refer to them in your style sheet. A Class can be
applied to multiple selections, whereas an ID uniquely identifies a specific selection within a Document. For
example, suppose you have an unordered list of products, and you want new products to appear in red. One
way to do it would be to manually add the style=”color: red” argument to each of the list items, like this:
<li style="color: red">Spraying Techniques for Fruit Trees</li>
To create a class, add a class= argument to the opening tag for the element.
For example, to make a list item part of the new class:
<li class="new">Spraying Techniques for Fruit Trees</li>
Then in the <style> area, add a style that defines the class as red. The only difference between defining a
class and redefining a standard tag is that you put a period in front of a class name:
<style>
.new {color: red}
</style>
To create an ID, add an id= argument to the tag, like this:
<li id="special">Spraying Techniques for Fruit Trees</li>
Then define the ID in the <style> area, preceding the ID name with a hash symbol (#) like this:
<Style>
#special {color: red}
</style>
Create two classes and apply them to items in a list. Then change the items’ formatting by applying
different styles to the classes.
9
<li class="appleton">Appleton Acres Big Sack of Bulbs, Daffodils</li>
<li class="appleton">Appleton Acres Big Sack of Bulbs, Hyacinths</li>
<li class="appleton">Appleton Acres Big Sack of Bulbs, Crocuses</li>
<li>Hawthorne Hills Hosta, 3-Pack</li>
<li>Sampson & Company All-Natural Herbicide</li>
</ol>
2 .Apply a class named sampson to the Sampson & Company items:
<ol>
<li class="sampson">Sampson & Company All-Natural Pesticide</li>
<li>Vickers and Vickers Fertilizer Sticks</li>
<li class="appleton">Appleton Acres Big Sack of Bulbs, Tulips</li>
<li>Jackson and Perkins Climbing Rosebushes</li>
<li>Easton Create-Your-Own Paving Stones Kit</li>
<li class="appleton">Appleton Acres Big Sack of Bulbs, Daffodils</li>
<li class="appleton">Appleton Acres Big Sack of Bulbs, Hyacinths</li>
<li class="appleton">Appleton Acres Big Sack of Bulbs, Crocuses</li>
<li>Hawthorne Hills Hosta, 3-Pack</li>
<li class="sampson">Sampson & Company All-Natural Herbicide</li>
</ol>
3. In the <style> area, create a style rule that makes items in the appleton class green:
<style>
hr {color: green; background-color: green; height: 3}.appleton {color: green}
</style>
4.In the <style> area, create a style rule that makes items in the sampson class blue:
<style>
hr {color: green; background-color: green; height: 3}.appleton {color: green}.sampson {color: blue}
</style>
5 .Save the file, and then refresh the Internet Explorer display.
Items 1 and 10 are blue, and items 3, 6, 7, and 8 are green.
Hyperlink formatting can be controlled by placing arguments in the <a> tag for each link, although
it’s tedious to do so. For example, to make an individual hyperlink magenta:
<a href="foliage.htm” style="color: magenta">Diagnosing Foliage Problems</a>
10
For example, to make all visited links magenta and all unvisited links black:
<style>
a: link {color: black}a: visited {color: magenta}
</style>
There are three additional pseudo-classes you can use with hyperlink styles:
focus: Used for links that are selected by using the keyboard but not yet activated. This pseudo-class
is not commonly used.
Hover: Used for links that the mouse is positioned over. Use this pseudo class to make a link change
color, become bold, and so on when the user points at it.
Active: Used for a link when it is clicked. Immediately after being clicked, the link goes to the
visited state.
Create style rules for various hyperlink states:
1 .In Internet Explorer, click the Diagnosing Foliage Problems hyperlink, and then click
Back to return to the referring page. Different colors identify visited and unvisited links.
2. In Notepad, in the <style> area, add these rules:
a:link {color: blue}
a:visited {color: green}
a:hover {color: lime}
a:active {color: red}
11
Displaying Graphics
In a word-processing program such as Microsoft Word, graphics are embedded in the document.
When you distribute the document to others, the graphics are included with it. In HTML, however, each
graphic displayed on a Web page is stored in a separate file, which must be stored on the Web server.
The following table lists the differences between the major Web-supported graphics formats.
After decide which graphics format to use for a particular image, next decision is how large the
graphic should be—that is, how many pixels should comprise it. This is called the image’s
resolution, and it is expressed in width and height. For example, an image that is 800x600 is 800
pixels wide and 600 pixels tall.
A graphic’s file size—how many bytes the file will take up on disk—has a direct relationship to its
resolution.
There are two ways of controlling the size (in pixels) of a graphic on a Web page. One is
to use a graphics-editing program to resize it before inserting it. This method results
in the smallest file size possible, which will make your page load more quickly. It is
also more work.
The other way is to use arguments within the HTML code to specify the height and width at which
the graphic is shown. The Web browser will scale the graphic down to the specified size when it
displays the page. With this method, the file size is larger, so the page takes longer to load.
Inserting Graphics
Inserting a graphic on a Web page is as simple as placing an <img /> tag where you want the
graphic to appear, like this:
12
<img src="logo.gif" />
To store your graphics in a subfolder of the folder containing the text files (to organize your files
more tidily), must refer to the graphic with the subfolder name, like this:
<img src="images/logo.gif" />
To refer to a file that is up one level in the folder structure, use two periods and a forward slash
(../), like this: <img src="../logo.gif" />
To force the image to the left or right side of the screen and wrap surrounding text around the image,
apply a float style rule that uses a left or right argument:
<img src="logo.gif" style="float: left" />
13
Insert a graphic that is located in a subfolder, and set it to float to the left of the text:
OPEN the index file in Microsoft Notepad and in Microsoft Internet Explorer.
14
It should be at the left margin, and not wrapped around the graphic.
To move down text vertically until the space occupied by the graphic becomes “clear, “use the clear style
rule. You apply this rule to the text’s tag, not to the graphic’s tag. For example:
<h2 style="clear: left">Recent Articles</h2>
The top horizontal line—and everything following it—to below the graphic:
1. Examine the document in Internet Explorer. Notice the placement of the text in relation
to the graphic.
2. In Notepad, add a clear style rule to the <hr /> tag near the top:
<hr style="clear: left" />
3 .Save the file, and refresh Internet Explorer. The horizontal line and everything that follows
it, appears below the graphic.
15
Controlling Image Size and Padding
Image size is expressed in pixels. You can specify only the width, and the height will be
resized proportionally, or vice versa. You can also specify both the width and the height.
For example: suppose this is your original image, which is 200 pixels high.
You could add a height=100 argument to the <img> tag, without specifying a width,
like this:
<img src="tree.gif" style="float: left" height="100" />
The image shrinks proportionally, like this.
However, if you specify both height and width of 100, like this:
<img src="tree.gif" style="float: left" height="100" width="100" />
The image will be distorted, like this.
16
5.Edit the <img> tag so that the image is 350 pixels in width and has 15 pixels of padding:
<img src="images/apple.png" style="float: left; padding: 15px" width=”350” />
6. Save the file and refresh Internet Explorer.
7. Edit the <img> tag so that the image floats to the right:
<img src="images/apple.png" style="float: right; padding: 15px" width="350" />
8. save the file and refresh Internet Explorer.
17
Hyperlinking from Graphics
To create text hyperlinks by using the <a> tag. Recall that you place the URL in the opening <a> tag, and
then you place the hyperlink text between the <a> and </a> tags. You create a graphical hyperlink in much
the same way, by placing an <img> tag in an <a> tag like this:
The graphic appears as usual in the document, but when the user moves the mouse pointer over it, the
pointer changes to a hand to indicate that the graphic is a hyperlink. By default, hyperlinked graphics have a
border that is the same color as hyperlinked text.
High-resolution graphics can make a page load slowly, but avoiding high-resolution graphics altogether can
limit your site’s effectiveness in delivering content. A compromise is to include thumbnail images, which
are low-resolution copies of the images that are linked to the larger, high-resolution versions.
Some Web development programs, such as Microsoft FrontPage, create thumbnail images automatically
when you set up a photo album page.
To create a thumbnail, you will need small versions of each of the graphics. You can create them by opening
the original graphic in a program like Photoshop or Paint Shop Pro, and then using that program to scale the
picture to a lower res
Placing an alt argument (traditionally called an alt tag, although it isn’t really a tag) in an <img> tag creates
alternate text for the graphic. This alternate text is a pop-up box that contains a text explanation of the
graphic, much like the title does for a hyperlink.
Alternate text is not just for decoration; it serves an important purpose for users who cannot view your
graphics for some reason. This might include visually impaired users who are accessing your page through
the use of a screen-reading program, and people who browse by using PDAs or cell phones.
Alternate text is simple to include; just place an alt="text" argument in the <img> tag like this:
The <figure> tag specifies self-contained content, like illustrations, diagrams, photos, code listings, etc.
While the content of the <figure> element is related to the main flow, its position is independent of the main
flow, and if removed it should not affect the flow of the document.
Use a <figure> element to mark up a photo in a document. The <figure> element also contains a caption:
<figure>
<img src="img_pulpit.jpg" alt="The Pulpit Rock" width="304" height="228">
<figcaption>Fig1. - A view of the pulpit rock in Norway.</figcaption>
</figure>
[UNIT-II COMPLETED]
19