Professional Documents
Culture Documents
UNIT-2
1. Discuss the difference between style and formatting?
Style:
“Styles” are collections of format specifications which can be applied all together to a
paragraph or a group of characters. The advantage of using styles to apply formatting is that you
can easily change the formatting of all paragraphs of a certain type (e.g. examples, section
headings or footnotes) simply by redefining the style.
Formats:
Formats are the text styles like boldface, underline, italics, superscripts, subscripts and
paragraphs.
The main difference between styles and formats are style defines structure and formats
but a format defines only the text styles.
CSS rules are defined as a property name followed by a colon and then a property value.
Individual rules are terminated by semicolons, with the final rule having an optional semicolon.
Syn:
Property-name1: value1; …. . . . . . property-nameN : value N;
Ex:
h1 { font-size : xx-large ; color : red; }
4. What are the different ways to add style sheets to Web pages?
A style is simply a set of formatting instructions that can be applied to a piece of text. We can
apply the styles to the HTML pages with the following ways.
Inline Style
Embedded Style
Linked Style
Imported Style
em {
font-size: 2em; color: green;
}
</style>
</head>
<body>
<h1> Welcome to CSS </h1>
<em>Hai to All </em>
</body>
</html>
The rel attribute is tells the browser what type of link we are using in HTML. The href
is a hyperlink of the stylesheet. The type attribute gives the relevant MIME type. The media
attribute can specify the type of media (screen viewing, printing and presentation) that can use
the web page.
Ex:
1. Create a CSS file that contains CSS style rules and Save as “Styles.CSS”.
2. Create a HTML file that contains the Matter and Save as “CSSExample.HTML”. Both files
are must be in a single folder.
CSS File:
Body {background-color: skyblue; font-size: 20px; font-color: red;}
H1 {font-family: times, times new roman, arial; font-size: 30px; font-color: green; }
HTML File:
<html>
<head>
<link rel=”Stylesheet” href=”styles.css” content=”text/css”>
</head>
<body>
<h1> Welcome to CSS </h1>
</body>
</html>
Font Style:
It has three values. Those are normal, italic or oblique (slanted)
Syn: font-style: normal | italic | oblique
Font Variant:
This is used to convert the all letters in the word will set small capitals.
Syn: font-variant: normal | small-caps
Font Weight:
The font-weight property sets the weight of the font to values like normal and
bold. It also has values bolder and lighter which are relative to any inherited font -
weight.
Syn:
font-weight: normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 |
800 |900
Font Size:
The font-size property sets the size of the displayed characters.
Syn: font-size: <absolute-size> | <relative-size> | <length> | <percentage>
Ex:
h1 { font-size: large } h2 { font-size: 12pt } h3 { font-size: 5cm }
Background Color:
The background-color property sets the background color of an element
Syn: background-color: <color> | transparent
Ex: body { background-color: white }
h1 { background-color: #000080 }
Background Image:
The background-image property sets the background image of an element.
Syn:background-image: <url> | none
Ex:
body { background-image: url("/images/monkey.gif") }
p { background-image: url("http://www.cclrc.com/pretty.png") }
h1 { background-image: none }
Background Repeat:
If the background image does not fill the whole element area, this description specifies
how it is repeated. The repeat-x value will repeat the image horizontally while the
repeat-y value will repeat the image vertically. Setting background-image to repeat
will repeat the image in both x and y directions.
Syn: background-repeat: repeat | repeat-x | repeat-y | no-repeat
Ex:
body { background-image: url(/images/monkey.gif) }
body { background-repeat: repeat-x }
Background Position
The background-position property gives the initial position of the background image
relative to the display or element depending on the attachment mode.
Syn:
background-position: [ percentage> | length ]{1,2} |
[[top | center | bottom] ||[left | center | right] ]
TEXT
Word Spacing:
The word-spacing property defines additional spacing between words. Negative values
are permitted which allows the letters to be closed up or even overlap.
Syn: word-spacing: normal | <length>
Ex: p { word-spacing: 0.4em }
h1 { word-spacing: -0.2em }
h2 { word-spacing: normal }
Letter Spacing:
The letter-spacing property defines additional spacing between characters. Negative values
are permitted.
Syn: letter-spacing: normal | <length>
Ex: h {letter-spacing: 0.2em }
p {letter-spacing: -0.1cm }
Vertical Alignment:
The vertical-align property defines the vertical positioning of an inline element (such as
some text or even an image) relative to the current baseline.
Syn: Vertical-align: baseline | sub | super | top | text-top | middle | bottom | text-bottom
|<percentage>
Text Transformation:
The text-transform property allows text to be transformed by one of four properties. Those
are capitalize, uppercase, lowercase and none.
Syn: text-transform: capitalize | uppercase | lowercase | none
Ex: h1 { text-transform: uppercase }
h2 { text-transform: capitalize }
Text Alignment:
The text-align property defines the horizontal alignment of text.
Syn: text-align: left | right | center | justify
Ex: h1 { text-align: center }
h2 {text-align: left }
h3 {text-align: right }
p {text-align: justify }
Text Indentation:
The text-indent property defines the amount of indentation that the first line of the element
has. A percentage refers to the parent element's width.
Syn: text-indent: <length> | <percentage>
Ex: p { text-indent: 5em }
BOX
Margin Setting:
Using this property we can set the margins for the web page or contents.
Syn:margin-top: <length> | <percentage> | auto
margin-right: <length> | <percentage> | auto
margin-bottom: <length> | <percentage> | auto
margin-left: <length>| <percentage> | auto
margin: [ <length> | <percentage> | auto ] {1,4}
Padding Setting
Padding is defined in much the same way as the margin. The main difference is that
negative padding is not allowed.
Syn: padding-top:<length> | <percentage>
padding-right: <length> | <percentage>
padding-bottom: <length> | <percentage>
padding-left: <length> | <percentage>
padding: [ <length> | <percentage>] {1,4}
Border Setting
Using this property we can control the Borders thickness
Syn:
border-top-width: thin | medium | thick | <length>
border-right-width: thin | medium | thick | <length>
border-bottom-width: thin | medium | thick | <length>
border-left-width: thin | medium | thick | <length>
border-width: [ thin | medium | thick | <length> ]{1,4}
Border Style
The border-style property sets the style of the border and must be specified for the border to
be visible
Syn:
border-style: [ none | dotted | dashed | solid | double | groove | ridge | inset |outset ] {1,4}
Float
The float property allows the user to wrap text around an element.
Syn: float: left | right | none
Clear
The clear property can be used by box-level elements to ensure that a previous floating
element is not adjacent to one of its sides.
Syn: clear: none | left | right | both
Ex: h1: {clear: left }
Example :
Exercise 12: Classes in CSS
<html>
<head>
<title> Classes in CSS </title>
<style type="text/css">
.darkblue
{
background-color: blue; color:white;
}
.skyblue
{
background-color: skyblue
}
</style>
</head>
<body class=”skyblue”>
<h1 class="darkblue"> T.J.P.S. COLLEGE, GUNTUR </h1>
</body>
</html>
The background colour of the div element is white, because the background-color
property is set to white. The background colour of the paragraph is also white, because the
background colour property is set to inherit, and the background colour of the parent element
(the div) is set to white.
The inherit value does not require that the parent element have the same property
set explicitly; it works from the computed value.
As a block element, div should induce a return, so if you want to provide style
information solely for a few words, or even a few letters, the best approach is to use the span
element, which as an inline element does not induce a return.
Ex: <p> Calling out <span style=”background-color: yellow; font-weight: bold ;”> Special
selections of text </span> isn’t hard with a span and css</p>
Exercise 14: CSS DIV and SPAN
<html>
<head> <title> CSS DIV and SPAN </title></head>
<body>
<div style="font-size:1cm; color:red; background-color:green;">
<p> This is First Part </p></div>
<div style="font-size:2cm; color:white; background-color:blue;">
<p>This is <span style="font-size:3cm; color:red; background- color:green;" > Second
</span> Part </p></div>
</body></html>