TechnoCSS2
TechnoCSS2
WEST BENGAL
CSS
(Cascading Style Sheet)
1
TECHNO INDIA UNIVERSITY
WEST BENGAL
background-color
background-image
background-repeat
background-attachment
background-position
2
TECHNO INDIA UNIVERSITY
WEST BENGAL
<!DOCTYPE html>
<html>
<body>
<h1 style="background-color:Tomato;">Tomato</h1>
<h1 style="background-color:Orange;">Orange</h1>
<h1 style="background-color:DodgerBlue;">DodgerBlue</h1>
<h1 style="background-color:MediumSeaGreen;">MediumSeaGreen</h1>
<h1 style="background-color:Gray;">Gray</h1>
<h1 style="background-color:SlateBlue;">SlateBlue</h1>
<h1 style="background-color:Violet;">Violet</h1>
<h1 style="background-color:LightGray;">LightGray</h1>
</body>
</html>
3
TECHNO INDIA UNIVERSITY
WEST BENGAL
4
TECHNO INDIA UNIVERSITY
WEST BENGAL
CSS background-color
Other Elements: You can set the background color for any HTML elements: Example:
Here, the <h1>, <p>, and <div> elements will have different background colors:
CSS background-image
The background-image property is used to set an image as a background of an
element. By default the image covers the entire element. You can set the
background image for a page like this.
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-image: url("paper1.gif");
margin-left:100px;
}
</style>
</head>
<body>
<h1>Hello Techno India University</h1>
</body>
</html> 7
TECHNO INDIA UNIVERSITY
WEST BENGAL
CSS background-repeat
By default, the background-image property repeats the background image horizontally and
vertically. Some images are repeated only horizontally or vertically. The background looks better if
the image repeated horizontally only.
background-repeat: repeat-x; background-repeat: repeat-y;
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<style> <style>
body { body {
background-image: url("gradient-bg.png"); background-image: url("gradient-bg.png");
background-repeat: repeat-x; background-repeat: repeat-y;
} }
</style> </style>
</head> </head>
<body> <body>
<h1>Hello Techno India University</h1> <h1>Hello Techno India University</h1>
</body> </body>
</html> </html>
1. background-color
2. background-image
3. background-repeat
We can use the shorthand property background: 4. background-attachment
5. background-position
12
TECHNO INDIA UNIVERSITY
WEST BENGAL
13
TECHNO INDIA UNIVERSITY
WEST BENGAL
• If you do not want to apply opacity to child elements, like in the previous
example, use RGBA color values. The following example sets the opacity
for the background color and not the text:
• We know that, we can use RGB as a color value. In addition to RGB, you can
use an RGB color value with an alpha channel (RGBA) - which specifies the
opacity for a color.
• An RGBA color value is specified with: rgba(red, green, blue, alpha). The
alpha parameter is a number between 0.0 (fully transparent) and 1.0
(fully opaque).
14
TECHNO INDIA UNIVERSITY
WEST BENGAL
16
TECHNO INDIA UNIVERSITY
WEST BENGAL
<!DOCTYPE html>
<html>
<body>
</body>
</html>
18
TECHNO INDIA UNIVERSITY
WEST BENGAL
Property Description
background Sets all the background properties in one declaration
background-attachment Sets whether a background image is fixed or scrolls with the rest
of the page
background-clip Specifies the painting area of the background
background-color Sets the background color of an element
background-image Sets the background image for an element
background-origin Specifies where the background image(s) is/are positioned
19
TECHNO INDIA UNIVERSITY
WEST BENGAL
Thank You
20