Cascading Style Sheets: - Deepa Acharya
Cascading Style Sheets: - Deepa Acharya
- Deepa Acharya
Introduction
XHTML is concerned primarily with content rather than the details of how that
content is presented by browsers.
When more than one style sheet applies to a specific tag in a document,
the lowest level style sheet has precedence
Inline style sheets have precedence over document style sheets, which
have precedence over external style sheets.
In a sense, the browser searches for a style property, starting with inline, until
it finds one (or there isn’t one)
Levels of Style Sheets
(continued)
This is done by listing the element hierarchy in the selector, with only
white space separating the element names.
Input.hover input.focus
Properties
The browser uses the first font in the list that it supports.
tells the browser to use Arial if it supports that font. If not, it will use Helvetica if it
supports it. If the browser supports neither Arial nor Helvetica, it will use Futura if it
can. If the browser does not support any of the specified fonts, it will use an
alternative of its choosing.
If a font name has more than one word, the whole name should be delimited by
single quotes, as in the following example: font-family: ‘Times New Roman’
A generic font can be specified as a font-family value.
The possible generic fonts and examples of each are
shown in below Table.
Each browser has a font defined for each of these
generic names.
Font Properties (continued)
font-size
Possible values: a length number or a name, such as Many relative font-size values are defined, including xx-small, x-
small, small, medium, large, x-large, and xx-large. In addition, smaller or larger can be specified.
font-variant:
The default value of the font-variant property is normal, which specifies the usual character font. This property can be set to
small-caps to specify small capital characters.
font-style
italic, oblique, normal
The letter-spacing property controls the amount of space between characters in text. The possible values of
letter-spacing are any length property values—for example, 3px.
<html>
<head> <title>Font Properties</title>
<style type = "text/css">
p.one
{
font-family: 'lucida calligraphy';
font-weight:bold; font-size:75pt;
color: purple;
letter-spacing:3px;
}
h1.two
{
font-family: 'cambria';
color: violet;
font-style:italics;
}
p.three
{
font: small-caps italic bold 50pt 'times new roman'
}
</style>
</head>
<body>
<p class = "one">Xtensible MArkup Language</p>
<h1 class = "two">CascaDING Style Sheets</h1>
<p class = "three">Java Script</p>
List properties
Two presentation details of lists can be specified in XHTML documents: the shape of the
bullets that precede the items in an unordered list and the sequencing values that precede the
items in an ordered list. The list-style-type property is used to specify both of these.
list-style-type property
Unordered lists
Bullet can be a disc (default), a square, or a circle
Set it on either the <ul> or <li> tag
On <ul>, it applies to list items
<h3> Some Common Single-Engine Aircraft </h3>
<ul style = "list-style-type: square">
<li> Cessna Skyhawk </li>
<li> Beechcraft Bonanza </li>
<li> Piper Cherokee </li>
</ul>
List properties (continued)
<html>
li.image {
list-style-image: url(bullet.png);
font-size:25pt;
</style> </head>
<body>
<ul>
</ul>
</body> </html>
On ordered lists - list-style-type can be used to
change the sequence values
216 colors
These colors, which are often called Web-safe colors, are displayable by Windows- and
Macintosh-based browsers, but may not be correctly displayed with some old terminals
__________________________________________
The color property specifies the foreground color of elements
<style type = “text/css”>
th.red {color: red}
th.orange {color: orange}
</style>
…
<table border = "5">
<tr>
<th class = "red"> Apple </th>
<th class = "orange"> Orange </th>
<th class = "orange"> Screwdriver </th>
</tr>
</table>
The background-color property specifies the background color of elements
ALIGNMENT OF TEXT
<html>
<head> <title>Background Image</title> <style type = "text/css">
body {
background-image:url(bg3.jpg);
}
p{
text-align: justify; color:white;font-size:25pt;
} </style> </head>
<body>
<p> Programming the Web </p>
</body>
</html>
Output
Text Decoration
The text-decoration property is used to specify some special features of
text. The available values are line-through, overline, underline, and none,
which is the default.
<html>
<head> <title>Text Decoration</title>
<style type = "text/css">
h1.one {
text-decoration: line-through;
}
h1.two {
text-decoration: overline;
}
h1.three {text-decoration: underline;}
</style>
</head>
<body>
<h1 class = "one">Web Programming</h1> <p>[This is line-through]</p><br/>
<h1 class = "two"> Web Programming </h1> <p>[This is overline]</p><br/>
<h1 class = "three"> Web Programming </h1>
<p>[This is underline]</p><br/>
</body> </html>
Output
THE <span> AND <div> TAGS
In many situations, we want to apply special font properties to less than a
whole paragraph of text. The <span> tag is designed for just this purpose.
<html>
<head> <title>span</title>
<style type = "text/css">
.spanviolet {
font-size:25pt;font-family:'lucida calligraphy';color:violet;
}
</style> </head>
<body>
<p > If we want to apply special font properties to less than a whole paragraph of
text,we can use <span class = "spanviolet"> SPAN TAG </span> which does this
job</p>
</body>
</html>
Output
It is more convenient, however, to be able to apply a style to a section of
a document rather than to each paragraph.
This can be done with the <div> tag. Its primary use is to specify
presentation details for a section or division of a document.
<html>
<head> <title>div</title>
<style type = "text/css">
.one {
font-size:20pt;font-family:'lucida calligraphy';
color:violet;
}
.two {font-size:25pt;font-family:'comic sans ms'; color:green;
}
</style> </head>
<body>
<div class = "one">
<p>Paragragh 1 under division 1</p>
<p>Paragragh 2 under division 1</p> <p>Paragragh 3 under
division 1</p>
</div> <div class = "two">
<p>Paragragh 1 under division 2</p> <p>Paragragh 2 under
division 2</p> <p>Paragragh 3 under division 2</p>
</div>
</body>
</html>
Output
The Box Model
On a given web page or a document, all the elements can have
borders.
The borders have various styles, color and width.
The amount of space between the content of the element and its
border is known as padding.
The space between border and adjacent element is known as
margin.
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
The Box Model (continued)
When two or more rules apply to the same tag there are rules for
deciding which rule applies
Document level
In-line style sheets have precedence over document style sheets
Document style sheets have precedence over external style sheets
Within the same level there can be conflicts
A tag may be used twice as a selector
A tag may inherit a property and also be used as a selector
Style sheets can have different sources
The author of a document may specify styles
The user, through browser settings, may specify styles
Individual properties can be specified as important
p.special {font-style: italic !important; font-size: 14}
Precedence Rules
Specificity
1. id selectors
2. Class and pseudo-class selectors
3. Contextual selectors
4. General selectors
Position
Essentially, later has precedence over earlier