CSS BACKGROUNDS

The CSS background property is a shorthand property used to set one or more background styles on an element.

Syntax

selector {
  background: value;
}

Common Examples

1. Background color

div {
  background: lightblue;
}

2. Background image

div {
  background: url("image.jpg");
}

3. Background image with no repeat

div {
  background: url("image.jpg") no-repeat;
}

4. Background image centered

div {
  background: url("image.jpg") no-repeat center center;
}

5. Background image covering the entire element

div {
  background: url("image.jpg") no-repeat center center / cover;
}

6. Background with color and image

div {
  background: #f5f5f5 url("image.jpg") no-repeat center / contain;
}

Individual Background Properties

Instead of the shorthand, you can use:

background-color: #3498db;
background-image: url("image.jpg");
background-repeat: no-repeat;
background-position: center;
background-size: cover;
background-attachment: fixed;
background-origin: padding-box;
background-clip: border-box;

Shorthand Format

background: <color> <image> <repeat> <attachment> <position> / <size>;

Example:

.hero {
  background: #000 url("hero.jpg") no-repeat center center / cover;
}

If you have a specific background effect in mind (such as a gradient, full-screen background, transparent overlay, or animated background), let me know and I can provide the appropriate CSS.

Comments

Popular posts from this blog

HTML | HTML INTRODUCTION

CSS GROUPING SELECTORS

HTML LISTS