Professional Documents
Culture Documents
CSS Characteristics
Allow you to control the layout and look of your page
easily
Styles define how to display HTML elements
Style web pages written in a markup language like
HTML, XHTML etc.
Allows the same markup page to be presented in
different styles for different rendering methods(on-
screen, in print etc.)
Specifies a priority scheme to determine which style
rules apply if more than one rule matches against a
particular element
CSS Syntax
Color:red;
Text-align:right;
Font-size:20pt;
» Relative Positioning
» Absolute Positioning
» Fixed Positioning
» Static Positioning
Relative Positioning
• defined by the top, bottom, left and right CSS properties
• determine how much an element will shift in relation to its “natural” position
• these four additional properties have default value of 0.
• they can accept both positive and negative values.
<body>
<p>this is a paragraph having no style</p>
<p style="position: relative; left: 35px;">this is a paragraph having relative
positioning</p>
<p style="position: relative; right:20px;">This is a paragraph having relative
positioning</p>
</body>
Absolute Positioning
• element will be positioned absolutely
• it will not affect other elements, and it will be positioned according to its
containing block
• if absolute positioning is used, top or bottom, left or right, and width and height
should be used as well.
<body>
<p>This is a paragraph having no style</p>
<p style="position: absolute; left: 35px; top: 50px; width: 150px; height: 250px;">This
is a paragraph having absolute positioning</p>
xyzabc
</body>
Fixed Positioning
• a subcategory of Absolute Positioning
• if an element has this type of position assigned, its viewport is the same as its
containing block.
• on the computer screen, an element using a fixed CSS positioning will not move
if a website is scrolled.
Media Types
Media Type Description
all For all media type device.
aural For speech synthesizers.
braille For Braille tactile feedback devices.
embossed For paged Braille printers.
handheld For handheld devices.
print For printed versions and print preview on
the screen.
projection For projected presentations such as
projectors and transparencies.
screen Computer screens.
tty Media using a fixed-pitch character grid,
such as teletypes, terminals, or portable
devices with limited display capabilities.
Tv Television-type devices.
Media Type(continued…)
@media print
{
p{font-family: Georgia, times, serif}
}
• Use the media attribute when linking to an external style
sheet. For example:
Advantages:
▪ CSS saves times
(CSS automatically apply the specified styles whenever that element occurs)
▪ Pages load faster
(less code means faster download times)
▪ Easy maintenance
(to change the style of an element, you only have to make an edit in one place)
▪ Superior styles to HTML
(CSS has a much wider array of attributes than HTML)
Disadvantages:
▪ Browser compatibility
Conditional Constructs
(The if-else conditional statement)