CSS2
CSS2
CSS supports a number of measurements including absolute units such as inches, centimeters, points, and so
on, as well as relative measures such as percentages and em units.
CSS ─ COLORS
CSS uses color values to specify a color. Typically, these are used to set a color either for the foreground of an element
(i.e., its text) or for the background of the element. They can also be used to affect the color of borders and other
decorative effects.
CSS - Backgrounds
<body>
<p style = "background-color:yellow;">
This text has a yellow background color.
</p>
</body>
</html>
Background Image
<html>
<head>
<style>
body {
background-image: url("/css/images/css.jpg");
background-color: #cccccc;
}
</style>
</head>
<body>
<h1>Hello World!</h1>
</body>
<html>
CSS - Fonts
Font Family
<html>
<head>
</head>
<body>
<p style = "font-family:georgia,garamond,serif;">
This text is rendered in either georgia, garamond, or the
default serif font depending on which font you have at your system.
</p>
</body>
</html>
Font Style
<html>
<head>
</head>
<body>
<p style = "font-style:italic;">
This text will be rendered in italic style
</p>
</body>
</html>
Font Weight
<html>
<head>
</head>
<body>
<p style = "font-weight:bold;">
This font is bold.
</p>
Font Size
<html>
<head>
</head>
<body>
<p style = "font-size:20px;">
This font size is 20 pixels
</p>
CSS - Margins
The margin property defines the space around an HTML element. It is possible to use negative
values to overlap content.
CSS - Paddings
The padding property allows you to specify how much space should appear between the content of
an element and its border –
The following CSS properties can be used to control lists. You can also set different values
for the padding on each side of the box using the following properties −
The padding-bottom specifies the bottom padding of an element.
The padding-top specifies the top padding of an element.
The padding-left specifies the left padding of an element.
The padding-right specifies the right padding of an element.
The padding serves as shorthand for the preceding properties.
<html>
<head>
</head>
<body>
<p style = "padding-bottom: 15px; border:1px solid black;">
This is a paragraph with a specified bottom padding
</p>
<html>
<head>
<style type = "text/css">
p.example1 {
border:1px solid;
border-bottom-color:#009900; /* Green */
border-top-color:#FF0000; /* Red */
border-left-color:#330000; /* Black */
border-right-color:#0000CC; /* Blue */
}
p.example2 {
border:1px solid;
border-color:#009900; /* Green */
}
</style>
</head>
<body>
<p class = "example1">
This example is showing all borders in different colors.
</p>
<body>
<p style = "border-width:4px; border-style:none;">
This is a border with none width.
</p>
CSS - Outlines
Outlines are very similar to borders, but there are few major differences as well −
An outline does not take up space.
Outlines do not have to be rectangular.
Outline is always the same on all sides; you cannot specify different values for
different sides of an element.
<body>
<p style = "outline-width:thin; outline-style:solid;">
This text is having thin outline.
</p>
<br />
<body>
<p style = "outline-width:thin; outline-style:solid;">
This text is having thin solid outline.
</p>
<br />
CSS - Cursors
The cursor property of CSS allows you to specify the type of cursor that should be displayed to the
user.
The following table shows the possible values for the cursor property −
1
auto
Shape of the cursor depends on the context area it is over. For example an I over text,
hand over a link, and so on...
2
crosshair
A crosshair or plus sign
3
default
An arrow
4
pointer
A pointing hand (in IE 4 this value is hand)
5
move
The I bar
6
e-resize
The cursor indicates that an edge of a box is to be moved right (east)
7
ne-resize
The cursor indicates that an edge of a box is to be moved up and right (north/east)
8
nw-resize
The cursor indicates that an edge of a box is to be moved up and left (north/west)
9
n-resize
The cursor indicates that an edge of a box is to be moved up (north)
10
se-resize
The cursor indicates that an edge of a box is to be moved down and right (south/east)
11
sw-resize
The cursor indicates that an edge of a box is to be moved down and left (south/west)
12
s-resize
The cursor indicates that an edge of a box is to be moved down (south)
13
w-resize
The cursor indicates that an edge of a box is to be moved left (west)
14
text
The I bar
15
wait
An hour glass
16
help
A question mark or balloon, ideal for use over help buttons
17
<url>
The source of a cursor image file
<html>
<head>
</head>
<body>
<p>Move the mouse over the words to see the cursor change:</p>
CSS - Scrollbars
This property can take one of the following values −
1
visible
Allows the content to overflow the borders of its containing element.
2
hidden
The content of the nested element is simply cut off at the border of the
containing element and no scrollbars is visible.
3
scroll
The size of the containing element does not change, but the scrollbars
are added to allow the user to scroll to see the content.
4
auto
The purpose is the same as scroll, but the scrollbar will be shown only
if the content does overflow.