152 Computer Application - 11
They are:
Style sheet (desktop publishing) -a feature of desktop publishing programs
Style sheet (web development) - W3C standards for web page style sheets
such as CSS or XSL.
+ Stylesheet language - computer languages that describe the presentation
of structured documents.
From the above three, the second type is used with HTML and forms
core part of the following sections of this chapter.
45.3. CASCADING STYLES SHEETS
_ Styles Sheets or CSS, is a way to style HTML. Whereas the HTML is the
‘content, the style sheet is the presentation of that document. Cascading style
‘sheets are a new way of formatting your page layout, text, fonts, images, and
almost anything you put on the page. They allow you to position things on your
page down to the exact pixel. Also, if a style is declared in the head section of
‘a page, a change to the style changes the style on the entire page. Here is the
general idea:
Let's say you created a style for a heading tag,
. In your style, you set the
“color of your H3 tags to red. Now if you have 10 H3 tags on the page, and
decide you would rather have your headings be blue, you would no longer need
‘to go back and change the font color for each heading. All you have to do is
‘change the style of your H3 tags from the color red to blue. Changing the style
‘once will adjust all of your H3 tags and they will now be all blue instead of
ted, with a lot less work. This gets even better if you use an external style
‘sheet for more than one page.Changing the style properties in the external style
sheet will now adjust every page that uses that style sheet, so you can avoid
editing each page individually to change it!
The same ways as HTML has attributes and value, CSS has properties
and value. The difference lies in the punctuation symbol used between
the above two words. The attributes and the value are separated by an
equal to (=) symbol, the properties and the value by a colon (:)~
15.4. BENEFITS OF CSS
Another of CSS’s boons is that you define things once, making it far
more efficient than defining everything in HTML on every page. This
means:
+ Pages download faster, sometimes by as much as 50%
You have to type less code, and your pages are shorter and neater-
+ ‘The look of your site is kept consistent throughout all the pages that WoAA
Cascaany
Me Sevte
” om tesa ne 153
mS Updating *¥esheet
198 yo
and errors’ OU" des
s OFS eaunasSSi8M and ge hain
ogra ited se general site maintenance aré made much easier,
Nis Wellauthored gg iggy” Stl" multiple HTML pages occur far ess often
, access Through myriad gays trOves the accessibility of web content, allowing
web users With disabititien Ce (handheld PDAs for example) and ensuing that
tation for browser-specific han’ °° still abl ample) ai
- lack: le to receive it. It also eliminates the need
‘working across alt mk* 8 tags, whi
Ee i voit nn ner, ears You ste has tener chance
jpitially Vaguely intimidatin,
ly important for the fun SS 8 a well-desi ;
fires move avray fron GeO MSD deslon, ant tar beet ane eoeining
il he he as been pivotal in helping
IL tags like Wow, | am totally redi
This will give you the following output in the browser
Wow, | am totally red!18.7
Cascading siyte Sheets
ice the dot that comes right before the
that this is a class definition and
1 same way we did before.
The name of our class is “redfont”. Nov
Name of the class. This notifies the browser
Not a tag definition. After that, we define the style the
So, if you want to declare one class that giv
gives you a green font, you would type the following:
es you a red font, and another that
Okay, now that we have our classes set up, we need to see how to use them
later on in the body section of the page. To use your class, all you need to do is
add the class=” “ attribute to the tag you wish to have the style of your class.
So, if you wanted a line of text to be red, you could add the class attribute to a
tag, like this:
| am red, so I'm
ee
#redfont { color:red }ima Computer Application - 11
Ygreentont { color:green }
STYLE>
HE
Nib ait tli i
And when you wish to use the ID later, use the ID=" * attr
[-
1 am red, so I'm important.
I am green, so there.
tags, If
you would like this effect to work across multiple pages, then you will want to
use an external style sheet, Well, suppose you would like to be able to use one
group of styles- but you want to use them on many pages at once
Open your text editor and create a new blank document. Now, type in just the
following information:
DIV { font-family:/Arial }
tedfont { color:red }
Now, save the file as “stylel.css” (You can use any name you wish, just
be sure you have the .css extention at the end).
= “stylesheet”
= "text/css”
eR18.10 Computer Application = 1
all, for all output devices.
15.11. THE BOX PROPERTIES
45.11.1. WIDTH PROPERTY
The width property lets you define a width for a section of your page, such as
‘a few sentences of text. If you set the width at 100 pixels, the text will wrap to
the next line when it gets to a length of 100 pixels, much like a table
IDIV>
This section of text willbe 100 pixels lon
This will give you the following:
This section of text will be 100 pixels long
15.11.2, HEIGHT PROPERTY
The height property lets you give a section a specific height. If you set the
height at 100 pixels, it should cut off the text after reaching a vertical length of
100 pixels, right? Well, it does....but you won’t see it because by default
everything is visible......
|
This will have a height of
100 pixels.
Here you have the height set at 100, but even with all the line breaks,
everything still shows up without a cut off:
15.11.3. OVERFLOW PROPERTY
aa 2 a property that lets us change what happens when something goes
‘yond our set width and height. The possible values are auto, scroll, hidde*
and visible. | am goin; e : w
tes ig to set it to “hidden”, i beyond
100 pixel cut off does not show up: ce nae
This will have a solid border. |
And you will get a long, solid border
[This will have a solid border. |
Let’s use the width property we learned earlier in this section
This will have a double
border.
You get a nice little double border:
| This will have a double border.
.Border-Width
you decide how thin or thick your border will be. The possible values
sorder-width can take are number of pixels, thin, medium and thick. If
e border-width to “thin”, you will get a thin border:15.14
15.13.4, Margin-Bottom
Same as above, but defines the bottom margin. The default is 0.
15.14, PADDING
15.141, Padding-Left
“The padding properties are much like the “cellpadding” property of a table,
‘except these let you define the padding for the left, right, top, and bottom
individually rather than all at once, The possible values that it can take are
“number of pixels, percentage value and auto. Here is an example of the
padding-left property :
THIS CHANGES EACH LETTER TO LOWERCASE.
The above code will produce the following output:
.
Th
15.20. LINE-HEIGHT “
Possible Valu “
normal
number of pixels
percentage
This lets you change the amount of space between lines of text. The possible
Values that line-height property can take are normal, number of pixels and
percentage. If you want each line to be 30 pixels apart, you could write ths:
_|
This text is indented 30 pixels on the L
‘And this is what you get:
. ; =
indented 30 pixels on the first line.
40.22. FONT-FAMILY L
‘The font-family property defines the type of font shown on the screen The
default name is whatever the browser uses normally, which tends to be Times {
‘New Roman (name of the font). If you want to change ‘the font to Arial, for i‘.
instance, you would write this:
The font for this section is Arial.
}
+
7
And you would get the text with an Arial font:
The font for this section is Arial.
‘omputer for this to work. So
The viewer must have the font jnstalled on their c
stick with the most common fonts for the most part.
f the font shown on the soreen- ‘The default
entage OF number of pixels. TO change
wuld do this:
15.22.1 Font-Size
The font-size property defines size 0
is medium but it can take values 1” perc
your font to a size of 40 pixels, you Wo3
1818
Computer Applicatio
And get thist Biase
The font is 40 pixels in size.
15.22.2 Font-Style
It might be simpler to just use the tag, but since the propert
| take normal, italics, oblique as its values. For example:
ne
y exists, it can
font-style:italic">The font is italic.
code results into following:
is italic.
Font-Variant
ly use I see for this one so far is that it lets you write in small caps if
to, The default is normal. If you want to write in small caps, do this:
Jets you control how bold the font is. The values it can take are
‘bolder, lighter and any value as a multiple of hundred from 100 to
er values (100-900) don’t seem to have any difference from one
how bold you can be!
OR
t property we'll go over is the color property. I probably have shows
already, but just in case I didn’t.
color property changes the forground color of a section, which is wv=l?
30, to change the color of some text:
s plain and this makes me think15.19
Ce
The eee
it would gi
15.24, BACKGROUND-COLOR
This property will let you add a back!
can add it to text like this:
ground color behind most anything, You
ZEPAN style="background-color:ye|
SPAN>
‘Also, you can use this in tables:
AAAGH! Pumpkin Background!
5,
You can change the background colour of a form box’ by using the following code.
|
Now try filling out THIS form.........
UTED Ee reevalues:
‘thin
‘medium
thick
Separate values bya _| div { border-top:2px solid
space in the following | green; }
order (those that are | div { border-top:thick double
not defined will use | #00FFO0; }
inherited or default15.23
ects -s
Cascading Style SHC _— -
Cas iB ae div { border-right-width:2px; }
border-right | Me right border vittea div { border-right-width:thin; }
width | thin |
| ‘medium
| =I jged as shorthand | Separate values by a | dv bordertight2px solid
border-right | property to set all the |) space in the toning peal a a
|| border-right properties | order (those that are | div { border-right:thick double |
at once, || not defined will use | #OOFFOO; )
| | inherited or default
| | inital values)
| border-right-width
border-right-style
| border-right-color
iv { border-bottom |
Declares the color of || Valid color names,
| the bottom border. | RGB values, | colorigreen; }
| hexidecimal notation, | div { border-bottom
or the predefined value | color:#OOFFOO; }
transparent. |
Tporder-bottom- | Declares the style of | None [av ( border-bottom-
style the bottom border. | stylesolid;) |
| | div { border-bottom-style:inset;)
| \ |
| ‘|
'
| |
the width of || Lengths or the |
Porder-bottom- || Declares the width of) Length
ae ; lowing predefined |
width tie bottom border. os: | swicththin:) |
| thin |
|| medium, :
thick
Sepacte vanes oa |
in the following " a
ser (those that are | 41V { border-bottom: thick
fot defined will use | double +H00FFOO; }
jnherited or default
initial values): | |
sic one |
porder-bottom-style |
porder-bottom-colorues Computer Application «I
|[vorderlet-syle | Declares the syle of | None diy { border-lef-syte oli, |
the left border. div { border-left-style-inset, }
orthe div { border-teft-width 2px, }
fatewing predefined | dv { border-leftwih hin.)
values |
thin
medium
thick
‘Separate values by div { border-left-2px solid
to setall the | space in the following | green, }
ft properties | order (those that are | div { border-teftthick double
atonce, not defined will use | HOOFFOO; }
inherited or default
Valid color names, div { border-color:green red
RGB values, olive; }
|| hexidecimal notation, { border-color:green; }
| orthe predefined value | div { border-color‘green red; )
transparent. div { border-color:green red
Separate the color for | blue; }
each border by a space,
|| declaring the colors for
|| the borders in the
| following order:
border-top-color
border-right-color
|| border-bottom-color
border-left-color
Undeclared values
work as further
shorthand notation. If
‘only one color value is
declared, all four
|| borders will use that
color. If two colors are
declared, the top and
bottom borders will
se the first color
while the right and left
borders will use the
second color. If three
‘colors are declared, the
top border will use the | |
first color, the right |
and left borders will
use the- r .
Cascading SOY ner 1 b0X tl )
——T peel oat to the le or | | |
aie offer content OF
rigtiper it should not be |
foated at al
iv (
div {visbilty:hidden; }
1
‘Declares the distance that div (top: 5px; } |
the top content edge of av |
the clement is offset om —
below the top edge of its |
containing block. The | =
position property of the | |
element must also be set |
| to a value other than
static. i
he ] |
Declares the distance that || Lengths, | div (right:15px; } fo
the right content edge of div (right: 2% } |
| the element is offset to
the left of the right edge
Declares the
| the left content edge of
the element is offset toTaepesandthe | Matelnmaion
| predefined valve
igus
Fecsarat [Desa thefintvarant orm
(58 Lie Popes
“Powsibe Vales
ample
a (isan
tise
za eee
| ecaaeang 200
beeen)
ere
mae
|Srepet
|e
\eoem
Sieosentc
\{sskoe
tien
| apes
SentMargin Properties
[Proper | Deserinon
earinop | De er
‘main boom | Decne he
Declares the lft
(rela alte
(55 Maren Properties
area he ia [Lang pecenage ante |
“Leng. cee a he
| Lengths, percentages andthe
edie vale sat
Separate values by aspacen he
{owing ede (ose ta a nt
fed il we heied deta
margin popes |i vale)
reins
mepitoror
map
Cece vloes woe srr
‘Sortandnton ely oe length
le i dele al fur mais wll,
{eat length two lenis are
declared, the top and Doom mains
hi as the rating whe height
Eadie margins wl se he second
Engh te ngs ae cared th |
topmgn whe ir ent, he
ip nd eR margins wil ws he
Setnd length dhe bo rarpn
ia te rd length
is { masinion S|
i (ragin13)
dv | maging)
{mare
iv {marge 5)
(arg boo 19)
3 roe
30S
———eEeE—_—__
Cac,
mt Ie Shey
Outtine Properties
3 rm Peserieton
ess
lars the width of the [Lengths rhe towing
=,
ae
padding othe | vate nt.
Semen.
Fah pang for
|tecemest |
Leng
vale at
| pring boas | Desi te
| rotor ping
forte clement
‘Decree let | Lens, percents
| padding forthe | value auto
pang
[Pate eee
fs
ee
| |i
outline [Used asa shorthand | Separate values by a space in
eeerotoriette — |sSeiocayose tera
ele pris [sose ative
ae ete tia
[bedastictop [Langs yeromaess ade pest |v
tangs [Dern te [ea oor bredleh nattiote Lor
mate
Fe. | Tee)
Detar uinc: [URL ned pac [apo
fepayaterms [cc pie
a l
teceranfomm | Dols te capitalization |
—
ee
[av (ue "
| ansfommuppereass
| iv {text
transformlowereass} |
pacer
RL rand he pnd | vee
ee Ween
fae
Steriund poco [URL ve and pected [a wow
stot asst |e none Sparen | nse)
vee yaspnde wen” [ay {cored om
eee
ar
tetra e elnl
ost bh
[itr tr
Dela clean [Angle alos deer
ofasond josewee ispe er
‘roar fhe (ore
| Eating reine vale:
Computer Application - 11
cars Becomes [Tien reo) ge (teat Si)
ror (sires.
div ( pitch: 120H; |
|
ete20%s) |
ie ede cr 2
[So [omer haere
oss av arma | i
. Saez eimomos” [iam =
e Tighervalees indent a loud
ee _ |
fllowed by dv (play
frre [eer ae | eee isaac.
Sepia wile be
spoken
‘owe teywords, |
searicdbyscs |
peat
Rhema one of he
[none
‘(ly
my)
repeat)
Se (pleyduringnone:) |
Declares the ices
ete vein
[spoken ot
eared
(See
janceneag
[eerie et |
a
(tes)
‘iy (retess0
ay (apne)
poco)
fh (speak beaderoes)
1 (spakhenderalvos
}
ai (speak
mera igs
avs
[iv (speak
ace)
pancation
Sie (spake
punetstion 0
Explain all the physical style elements in HTML with examples,
(May 2008)
‘What are cascading style sheets? Explain al types of cascading syle
sheets using suitable HTML code {un 2006)
‘What are the various types of stylesheets available in computer world?
Which is used for web development?
‘What is the difference between style attribute and syle element
Explain using examples.
Give an example to explain how class attribute is used in sh
Give an example to explain how ID attribute is used in syle el
7. Give examples to explain the various propeties to change
text.
8. Give examples to explain the vaious prop
border.
9.
Give examples to explain the various properties
of the text.