Module2-WT HTML Css
Module2-WT HTML Css
CSS Introduction
Introduction
• HTML is concerned primarily with content rather than the details of how that
content is presented by browsers
1. Inline
– An inline CSS is used to apply a unique style to a single HTML element.
– Inline style specifications appear within the opening tag and apply only to the
content of that element
– <head>
<style>
body {background-color: pink;}
h1 {color: red;}
p {color: green;}
</style>
</head>
3. External style sheets
– It can be applied to any number of documents
– External style sheets are in separate files, potentially on any server on the
Internet.
– The file must not contain any HTML code, and must be saved with a .css
extension.
• If no style sheet provides a value for a particular style property, the browser default
property value is used.
• Internal.html
• inline.html
• External.html
• Refer Slide No 13
Refer Slide No 13
• Refer Slide No 13
Selector Forms
A selector specifies the elements to which the following style information applies.
1. Simple Selector
• The selector is a tag name or a list of tag names, separated by commas
• h1, h3
– P
h1 {property-value list}
h2, h3 {property-value list}
simpleSelector.html
2. Class Selectors
• Used to allow different occurrences of the same tag to use different style
specifications
• The class you want on a particular occurrence of a tag is specified with the class
attribute of the tag
• For example,
<p class = “abc">
<h1> Hello</h1>
</p> Class_Selector.html
<p class = “efg">
<h2>MCA</h2>
</p>
3. Generic Selectors
A generic class can be defined if you want a style to apply to more than one kind of
tag
• A generic class must be named, and the name must begin with a period
• Example,
.NIE {property-value list}
• General form:
#specific-id {property-value list}
• Example:
#Cs{font-size: 20} Id_selector.html
• The specified style is applied to an element only if the element is in the specified
context.
Contectual_Selector.html
6. Pseudo Classes
• Pseudo classes are styles that apply when something happens, rather than because
the target element simply exists
• The two pseudo classes for styling links are link and visited
• The link pseudo class is used to style a link that has not been selected
• Pseudo_selector.html
7. The Universal Selector
The universal selector, denoted by an asterisk (*), applies its style to all elements in
a document.
• *{property-value list}
• universal_selector.html
Property Value Forms
• There are 60 different properties in 7 categories:
– Fonts
– Lists
– Alignment of text
– Margins
– Colors
– Backgrounds
– Borders
• Keywords property values are predefined - left, small, …
– Not case sensitive
• Length - numbers, maybe with decimal points
• Units:
– px - pixels
– in - inches
– cm - centimeters
– mm - millimeters
– pt - points
– pc - picas (12 points)
– em -is the value of the current font size in pixels
– ex-height
– No space is allowed between the number and the unit specification e.g., 1.5
in is illegal!
• Percentage - just a number followed immediately by a percent sign
• URL values
– url(protocol://server/pathname)
• Colors
– Color name
– rgb(n1, n2, n3)
• Numbers can be decimal or percentages
– Hex form: #XXXXXX
fuchsia
or rgb(255, 0, 255)
or #FF00FF
Font properties
1. Font-Families
– Specify a list of font names - browser uses the first in the list it has
• Browser has a specific font for each
h2 { font-family: serif; }
2. Font Sizes
• The font-size property in CSS is used to specify the height and size of the font. It
affects the size of the text of an element.
• Its default value is medium and can be applied to every element. The values of
this property include xx-small, small, x-small, etc.
Absolute-size
• It is used to set the text to a definite size. Using absolute-size, it is not possible to
change the size of the text in all browsers.
Relative-size
• It is used to set the size of the text relative to its neighboring elements. With relative-
size, it is possible to change the size of the text in browsers
<p style="font-
size:small;">
3. 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 letters.
p { font-variant: small-caps; }
4. Font Style
– italic, oblique , normal
h2 { font-style: italic; }
h3 { font-style: oblique; }
h4 { font-style: normal; }
5. Font Weight
• degrees of boldness
– bolder, lighter, bold, normal
• Could specify as a multiple of 100 (100 – 900)
• The possible values of letterspacing are normal or any length property value.
• Positive values increase the letter spacing, negative values decrease it.
– Controls whether the element has a border and if so, the style of the border
– Border width can be specified for any of the four borders (e.g., border-top-width)
– Border color can be specified for any of the four borders (e.g., border-top-color)
– Programs\borders.txt
Programs\borders.html
Margins and Padding
• The margin is the space between the border of an element and the element’s
neighbors.
• When there is no border, the margin plus the padding is the space between the
content of an element and its neighbors.
• When the element has a background: The background extends into the
padding, but not into the margin.