Background properties in CSS allow you to customize and style the background of elements on a web page. They provide control over background images, colors, positioning, repetition, and more. Here's an explanation of the key background properties in CSS:
In these chapters, you will learn about the following CSS background properties:
In CSS (Cascading Style Sheets), the background color property is used to define the background color of an element on a web page. It allows you to specify a color value or keyword that determines the background color of the content area of an element.
The background color property can be applied to various HTML elements, such as <body>, <div>, <p>, <span>, etc. Here's the basic syntax:
selector { background-color: value; }
The selector is the HTML element or class/id selector to which you want to apply the background color. The value represents the desired color for the background.
h1 { background-color: green; } div { background-color: lightblue; } p { background-color: yellow; }
To set a background image using CSS, you can use the background-image property. Here's an example of how you can add a background image to an element:
selector { background-image: url("path/filename"); }
In the example above, replace "path/filename" with the actual path to your image file.
You can also specify additional properties to control how the background image is displayed, such as background-repeat, background-size, and background-position. Here's an example that includes some of these properties:
body { background-image: url("rose.png"); }
Feel free to adjust these properties according to your specific requirements.
In CSS, you can control how a background image repeats using the background-repeat property. This property allows you to specify whether the background image should repeat horizontally, vertically, both, or not at all. Here are the possible values for the background-repeat property
By default, the background-image property repeats an image both horizontally and vertically.
Some images should be repeated only horizontally or vertically, or they will look strange, like this:
The background-repeat property accepts the following values:
body { background-image: url("gradient_bg.png"); background-repeat: repeat-x; }
In the example, the background image specified by url("image.png") will repeat only horizontally within the <div> element. It will create a row of repeated images to cover the width of the element. By controlling the background-repeat property, you can achieve different effects with background images, such as seamless patterns, tiled backgrounds, or single instances of an image.
In CSS, the background-position property is used to control the positioning of a background image within its containing element. It specifies where the background image should be placed relative to the element's padding box.
The background-position property accepts one or two values, which can be specified using keywords, percentages, or length values.
The background-position property is used to specify the position of the background image.
Here are the different ways to specify the background-position values:
Keywords
Percentages
Length values
The background-position property can also be combined with the background-repeat property to control both the positioning and repetition of the background image.
It's worth noting that if only one value is provided for background-position, the second value is assumed to be 50%. This centers the background image vertically if not specified explicitly.
By adjusting the background-position property, you can precisely control where the background image appears within its container and create various visual effects.
body { background-image: url("img_tree.png"); background-repeat: no-repeat; background-position: right top; }
In CSS, the background-attachment property is used to control whether a background image scrolls with the content or remains fixed in place when the content is scrolled.
The background-attachment property specifies whether the background image should scroll or be fixed (will not scroll with the rest of the page):
body { background-image: url("img_tree.png"); background-attachment: fixed; }
The background-attachment property accepts the following values:
By utilizing the background-attachment property, you can create different visual effects and control how background images behave in relation to scrolling content.
In CSS, the background-origin property is used to control the positioning of the background image relative to its containing element's padding box, border box, or content box.
The background-origin property accepts the following values:
Here's an example that demonstrates the usage of background-origin:
body { background-image: url("img_tree.png"); background-origin: border-box; }
By adjusting the background-origin property, you can control the positioning of the background image within its containing element and achieve different visual effects.
In CSS, the background-clip property is used to control how the background image or color is clipped or displayed relative to the element's padding box, border box, or content box.
The background-clip property accepts the following values:
Here's an example that demonstrates the usage of background-clip:
body { background-image: url("img_tree.png"); background-clip: border-box; }
By adjusting the background-clip property, you can control how the background image or color is displayed and clipped relative to the element's box model, achieving different visual effects.
In CSS, the background-blend-mode property is used to specify how the background images and background color of an element should blend or interact with each other.
The background-blend-mode property accepts various blending modes, similar to the blending modes used in image editing software. These blending modes determine how the colors of the background images and background color are combined.
The background-blend-mode property can be applied to individual background layers or to all background layers combined.
body { background-image: url("img_tree.png"); background-color: #ff0000; background-blend-mode: multiply; }
Here are some commonly used blending modes for the background-blend-mode property:
By utilizing different blending modes with the background-blend-mode property, you can achieve various creative effects and control how the background images and color interact with each other.
<!DOCTYPE html> <html lang="en"> <head> <title>Tutor Joes</title> <link href="https://fonts.googleapis.com/css?family=Pacifico" rel="stylesheet"> <style> html{ background:white; } body{ background: teal; background-image: url(jerry.png); color:white; background-repeat: no-repeat; background-size: 100px 100px; background-position: top right; height: 800PX; width: 800px; } h1{ font-family: 'Pacifico', cursive; font-weight:normal; font-variant: small-caps; color:yellow; } p{ font-style:italic; font-size: 25px; } span{ font: bold 12pt Arial; } </style> </head> <body> <h1>Background Properties</h1> <p> <span>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Qui, placeat eius! Error deserunt eaque sed non, laboriosam quaerat veritatis </span>veniam possimus? Facilis corporis quae at alias esse optio sint dignissimos.Lorem ipsum dolor sit, amet consectetur adipisicing elit. Qui, placeat eius! Error deserunt eaque sed non, laboriosam quaerat veritatis veniam possimus? Facilis corporis quae at alias esse optio sint dignissimos. </p> </body> </html>To download raw file Click Here
These background properties can be combined to create visually appealing backgrounds for elements on your web page. By leveraging background images, colors, gradients and other settings, you can enhance the overall design and aesthetics of your website.
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions