XML Lecture-4 2
XML Lecture-4 2
)
Presentation: Creating the End Product
Attribute Selection
planet[atmosphere]
planet[atmosphere="breathable"]
planet[atmosphere~="sweet"]
planet[populace|="barbaric"]
• Similar to the previous version, a selector with the operator
|= matches an item in a hyphen-separated value list as long
as the list begins with the value in the selector. This matches
<planet populace="barbaric-hostile">.
planet:lang(en)
planet.uninhabited
1. Ancestry
For example:
• The > operator works only when there is one level separating
the two elements.
• To reach an element at an arbitrary depth inside another
element, list them in the selector, separated by spaces. For
example:
<table>
<title>A plain ol' table</title>
<tgroup>
<tbody>
<row>
<entry>
<para>Hi! I'm a table cell paragraph.</para>
...
<chapter><title>Classification of Bosses</title>
<sect1><title>Meddling
Types</title>
<sect2>
<title>Micromanagers
</title>
...
• You can match the last two <title> elements with this selector:
chapter * title
• matches every <para> that follows a <title> and turns off its
initial indent. This works only for elements that are right next to
each other; there may be text in between, but no other elements.
• The <h1> element matches three of these rules. The net effect is
to render it with the font ITC Garamond at 24- point size in the
color blue.
• What if there's a conflict between two or more values for the
same property? For example, there might be another rule in
this stylesheet that says:
h1:first-child {
color: red
}
When Multiple Rules Match
• An <h1> that is the first child of its parent would have conflicting
values for the color property.
• CSS has well-defined rules for resolving such conflicts. The basic
principle is that more specific selectors override more general
selectors. The following list outlines the decision process:
• means that the <b> element has a font size that is twice its
parent's.
2. Units of Measurement
block
inline
• An inline is content that doesn't interrupt the flow of text in a
block.
• It can set properties that don't affect the flow, such as font-
family and color, but cannot have properties related to
blocks, such as margins and padding.
• Examples of inlines are emphasis, keywords, and hypertext
links.
invisible
• Every block has an invisible box that shapes its content, keeps it a
healthy distance from its neighbors, and defines a canvas on which
to paint.
• Figure below shows all the parts of this box model. Immediately
surrounding the content of the block is a rectangular buffer of
space called the bounding box.
• Its distance from the content is known as padding. The perimeter
of this region, called the boundary, is sometimes displayed as a
rule or border on one, two, three, or all four sides.
• The thickness of these rules is measured outward. Outside the
boundary is another envelope of space, defined by four widths
called margins.
4 Properties for Block Elements
• A margin is the distance between the bounding box of an element and that of
any neighboring (or containing) element. The four sides of a box have their
own margin property: margin-left, margin-right, margin-top, and margin-
bottom.
• The value can be a length or a percentage of the containing element's width.
• The margin property is shorthand for defining all four sides of the margin. Its
value is a space-separated list containing between one and four lengths or
percentages.
• If only one value is specified, that value applies to all four sides. If there are
two values, the first sets the top and bottom margins and the second sets the
left and right margins.
• If there are three values, the first assigns the top margin, the second assigns
both the left and right margins, and the third assigns the bottom margin.
• Finally, if four values are specified, they correspond to the top, right, bottom,
and left margins, respectively.
1. Margins
• Unspecified margins default to zero. Thus the following rules are equivalent:
para { margin-left: 10em; margin-right:
10em; margin-top: 5% } para { margin: 5%
10em 0 }
• In both cases, the <para> element is defined with left and right margins of 10
em, a top margin of 5% of the containing element's size in the vertical
dimension (i.e., its height), and no bottom margin.
• Negative values are acceptable. The result of a negative margin is to push the
bounding box outside its container's box by that amount.
• To create the effect of text spilling outside a colored region, we use this
stylesheet for an HTML file:
body { background-color:
silver } p { right-margin:
-15% }
2. Borders
thin
medium (the default)
thick
2. Borders
solid dashed
dotted groove
ridge double
inset outset
• The padding property lines the inside of the border with space to
compact the text and keep the border from colliding into it.
• The value of this property is a space-separated list of between one
and four length measurements.
• The application of lengths to sides is the same as it is with the
margin property.
Let's expand on our previous warning example by giving it a border,
warning { display: block;
border: thick solid gray;
}
warning:before {
content: "WARNING!";
font-weight: bold;
color: red }
warning
Figure 4.11, A warning inside a border
4 Alignment and indentation
left
Align text with the left border (ragged right).
right
Align text with the right border (ragged left).
center
Center each line within the block (ragged left and right).
justify
Expand each line to reach both left and right borders of the
block.
4 Alignment and indentation
This collects all the oddball fonts like Comic Strip, Ransom
Note, and Wild West.
The line-height property affects the total height of the font plus
the whitespace above it.
para1 { line-height: 1 }
para2 { line-height: 2 }
para3 { line-height: 1.5
}
4. Font style and weight
normal
The traditional, upright version of the font.
italic
An italic version of the font, if available, or the oblique version.
oblique
The oblique version, if available, or the normal font with a slight
slant effect.
4. Font style and weight
inherit
Whatever setting the parent element has.
em { font-style: italic }
em:lang(ja) { font-family:
...;
font-style: normal }
• The font-weight property controls how bold or light a font is. The
following keyword values are defined:
light
A light and airy version of the font, if available. Otherwise,
the user's system may generate one automatically.
normal
The standard variant of the font.
bold
A darker, heavier version of the font, if available. Otherwise,
the user's system may generate one automatically.
• There are also relative keywords, which decrease or increase the
weight with respect to the parent's property:
lighter
Decreases the weight by one increment.
bolder
Increases the weight by one increment.
• counter-reset: It sets the counter value back to zero when the element is
processed.
1. Counters
numberedlist { counter-reset:
list_item_number; } listitem {
counter-increment:
list_item_number; }
listitem:before { content: counter(list_item_number) ". ";
}
Now, each list will start counting
at 1: First list:
1.Alpha
2.Bravo
3.Charlie
4.Delta
Second list:
1.Fee
2.Fi
3.Fo
4.Fum
Quiz-6
• Before creating the stylesheet, let's make some changes to the XHTML file from
previous slide to help it take full advantage of CSS's capabilities. First, we'll add
some <div> elements to act as section containers. Since HTML suffers from a
lack of block containers, <div> was added to the specification as a general-
purpose division element. However, since it's so generic, we'll have to use a
class attribute with it to differentiate its roles. So we will also be adding class
attributes to other elements, increasing the number of things that can be
assigned unique styles.
Example 4.1, The Revised XHTML Document
<?xml version="1.0"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Evil Science Institute</title>
<link rel="stylesheet" href="style1.css"/>
</head>
<body>
<h1>The Evil Science Institute</h1>
<p class="bigp"><em>Welcome</em> to Dr. Indigo
Riceway's <span class="inst">Institute for
Evil Science!</span></p>
<div class="toc">
<h2>Table of Contents</h2>
<ol>
<li><a href="#staff">Meet Our Staff</a></li>
<li><a href="#courses">Exciting Courses</a></li>
<li><a href="#research">Groundbreaking Research</a></li>
<li><a href="#contact">Contact Us</a></li>
</ol>
Example 4.1, The Revised XHTML Document
<a name="staff" />
<div class="section" id="staff">
<h2>Meet Our Staff</h2>
<dl>
<dt><span class="person"><a
href="riceway.html">Dr. Indigo
Riceway</a></span></dt>
<dd>
<img src="images/riceway.gif" width="60"
height="80" /> Founder of the <span
class="inst">Institute</span>, inventor of the
moon magnet and the metal-eating termite,
three-time winner of Most Evil Genius award.
Teaches Death Rays 101, Physics, Astronomy,
and Criminal Schemes.
</dd>
<dt><span class="person"><a
href="grzinsky.html">Dr. Ruth "Ruthless"
Grzinsky</a></span></dt>
<dd>
Example 4.1, The Revised XHTML Document
<img src="images/grzinsky.gif" width="60"
height="80" /> Mastermind of the Fort Knox
nano-robot heist of 2002.
Teaches Computer Science, Nanotechnology, and
Foiling Security Systems.
</dd>
<dt><span class="person"><a
href="zucav.html">Dr. Sebastian
Zucav</a></span></dt>
<dd>
<img src="images/zucav.gif" width="60"
height="80" /> A man of supreme mystery
and devastating intellect.
Teaches Chemistry, Poisons, Explosives, Gambling, and Economics
of Extortion.
</dd>
</dl>
</div>
<a name="courses" />
<div class="section" id="courses">
<h2>Exciting Courses</h2>
<p>Choose from such intriguing subjects as...</p>
<ul>
<li>Training Cobras to Kill</li>
<li>Care and Feeding of Mutant Beasts</li>
<li>Superheros and Their Weaknesses</li>
<li>The Wonderful World of Money</li>
<li>Hijacking: From Studebakers to Supertankers</li>
</ul>
</div>
<a name="research" />
<div class="section" id="research">
<h2>Groundbreaking Research</h2>
<p>Indigo's <span class="inst">Evil Institute</span> is a world-
class research facility. Ongoing projects include:</p>
<h3 class="projectname">Blot Out The Sky</h3>
<p class="projdesc">A diabolical scheme to fill the sky with garish
neon advertisements unless the governments of the world agree to
pay us one hundred billion dollars. <span class="laughter">Mha ha
ha ha ha!</span></p>
<h3 class="projectname">Killer Pigeons</h3>
<p class="projdesc">A merciless plan to mutate and train pigeons to
become efficient assassins, whereby we can command <em>huge
bounties</em> by blackmailing the public not to set them loose.
<span class="laughter">Mha ha ha ha ha!</span></p>
<h3 class="projectname">Horror From Below</h3>
<p class="projdesc">A sinister plot so horrendous and terrifying,
we dare not reveal it to any but 3rd year students and above. We
shall only say that it will be the most evil of our projects to
date! <span class="laughter">Mha ha ha ha ha!</span></p>
</div>
<a name="contact" />
<div class="section" id="contact">
<h2>Contact Us</h2>
<p>If you think you have what it takes to be an Evil Scientist,
including unbounded intellect, inhumane cruelty and a sincere
loathing of your fellow man, contact us for an application. Send
a self-addressed, stamped envelope to:
</p>
<address>The Evil Science Institute, Office of
Admissions,
10 Clover Lane,
Death Island,
Mine Infested Waters off the Coast of Sri Lanka</address>
</div>
Example 4.2, A Stylesheet for an XHTML Document
/*
SECTIONS
*/ (1)
body { (2)
color: black;
background-color: silver;
}
div li { (5)
font-size: 1.4em;
font-family: sans-serif;
}
dd {
color: black; font-size: 1.2em; margin: 1em;
}
*/ ------INLINES -----*/
em {
font-style: italic;
font-weight: bold;
}
.laughter { color:
purple;
font-style: italic;
font-weight: bold;
}
.person {
font-weight: bold;
}
.inst {
font-style: italic;
}
(1)Comments can be helpful in making stylesheets more readable.
(3)The selector can .section match any element that has the
attribute class="section". Here, we use it only with <div>
elements, so it's okay to leave out the element name.
(5)This is another kind of context selector, one where the two space-
separated elements must lie in the same ancestral chain.