Introduction To CSS - Prelim
Introduction To CSS - Prelim
</p>
Example:
<!DOCTYPE html>
<html>
<head>
<style>
p{
The selector points to the HTML element you want text-align: center;
to style. The declaration block contains one or color: red;
more declarations separated by semicolons. }
</style>
Each declaration includes a CSS property name and </head>
a value, separated by a colon. A CSS declaration <body>
always ends with a semicolon, and declaration
blocks are surrounded by curly braces. <p>Every paragraph will be affected by the
style.</p>
Example: <p id="para1">Me too!</p>
<p>And me!</p>
<!DOCTYPE html>
<html> </body>
<head> </html>
<style>
p{ 2. The id Selector
color: red;
text-align: center; The id selector uses the id attribute of an
} HTML element to select a specific element.
</style> The id of an element should be unique
</head> within a page, so the id selector is used to
<body> select one unique element!
<p>Hello World!</p>
To select an element with a specific id, color: red;
write a hash (#) character, followed by the }
id of the element. </style>
The style rule below will be applied to the </head>
HTML element with id="para1": <body>
Example:
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: linen;
}
h1 {
color: maroon;
margin-left: 40px;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Inline Styles
</body>
</html>
Hexadecimal Colors Example:
<!DOCTYPE html>
Hexadecimal color values are supported in all <html>
major browsers. A hexadecimal color is specified <head>
with: #RRGGBB, where the RR (red), GG (green) <style>
and BB (blue) hexadecimal integers specify the #p1 {background-color:rgb(255,0,0);}
components of the color. All values must be #p2 {background-color:rgb(0,255,0);}
between 00 and FF. For example, the #0000ff value #p3 {background-color:rgb(0,0,255);}
is rendered as blue, because the blue component is #p4 {background-color:rgb(192,192,192);}
set to its highest value (ff) and the others are set to #p5 {background-color:rgb(255,255,0);}
00. #p6 {background-color:rgb(255,0,255);}
</style>
Example: </head>
<!DOCTYPE html>
<html> <body>
<head> <p>RGB colors:</p>
<style> <p id="p1">Red</p>
#p1 {background-color:#ff0000;} <p id="p2">Green</p>
#p2 {background-color:#00ff00;} <p id="p3">Blue</p>
#p3 {background-color:#0000ff;} <p id="p4">Grey</p>
#p4 {background-color:#ffff00;} <p id="p5">Yellow</p>
#p5 {background-color:#ff00ff;} <p id="p6">Cerise</p>
</style> </body>
</head> </html>
The background-image property specifies an image Showing the background image only once is also
to use as the background of an element. By default, specified by the background-repeat property:
the background-image property repeats an image
both horizontally and vertically so it covers the Example:
entire element. <!DOCTYPE html>
<html>
Example: <head>
<!DOCTYPE html> <style>
<html> body {
<head> background-image: url("img_tree.png");
<style> background-repeat: no-repeat;
body { }
background-image: url("paper.gif"); </style>
} </head>
</style> <body>
</head>
<body> <h1>Hello World!</h1>
<p>W3Schools background image example.</p>
<h1>Hello World!</h1> <p>The background image is only showing once,
<p>This page has an image as the background!</p> but it is disturbing the reader!</p>
</body> </body>
</html> </html>
To repeat an image horizontally set: background- The position of the image is specified by
repeat: repeat-x; To repeat an image vertically set: the background-position property:
background-repeat: repeat-y;
Example:
Example:
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<style> <style>
body { body {
background-image: url("gradient_bg.png"); background-image: url("img_tree.png");
background-repeat: repeat-x; background-repeat: no-repeat;
} background-position: right top;
</style> margin-right: 200px;
</head> }
<body> </style>
</head>
<h1>Hello World!</h1> <body>
<p>Here, a backgound image is repeated only
horizontally!</p> <h1>Hello World!</h1>
<p>W3Schools background no-repeat, set position
</body> example.</p>
</html>
<p>Now the background image is only shown once, body {
and positioned away from the text.</p> background: #ffffff url("img_tree.png") no-repeat
<p>In this example we have also added a margin right top;
on the right side, so the background image will margin-right: 200px;
never disturb the text.</p> }
</style>
</body> </head>
</html> <body>
<h1>Hello World!</h1>
</body>
</html>
Example:
<!DOCTYPE html>
<html>
<head>
<style>