WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

CSS Backgrounds


Background Color

The background-color primarily utilized for foundation shade of a component.

The foundation shade of a page you can set:

Example

body {
    foundation shading: #6600FF;
}
Try it yourself »

With CSS, a shading is regularly indicated by:

  • a legitimate shading name - like "red"
  • a HEX esteem - like "#ff0000"
  • an RGB esteem - like "rgb(255,0,0)"

Look at CSS Color Values for a total rundown of conceivable shading values.

In this precedent beneath, the <h1>, <p>, and <div> components have diverse foundation colors:

Example

h1 {
    foundation shading: #284370;
}

div {
    foundation shading: #bc6a32;
}

p {
    foundation shading: #97a033;
}
Try it yourself »

Background Image

The background-image for the most part utilized for pictures as foundation of a component.

image is rehashed it spread the whole component.

The foundation picture for a page can be set look like this:

Example

body {
    foundation picture: url("architecture-structures cars.jpg");
}
Try it yourself »

Below is a case of a terrible blend of content and foundation picture. The content is barely readable:

Example

body {
    foundation picture: url("architecture-structures cars.jpg");
}
Try it yourself »

Background Image - Repeat Horizontally or Vertically

By default, the background-image property rehashes a picture both on a level plane and vertically.

Some pictures ought to be rehashed just on a level plane or vertically, or they will look weird, as this:

Example

body {
    foundation picture: url("architecture-structures cars.jpg");
}
Try it yourself »

If the picture above is rehashed just on a level plane (background-rehash: rehash x;), the foundation will look better:

Example

body {
    foundation picture: url("architecture-structures cars.jpg");
    foundation rehash: rehash x;
}
Try it yourself »

Background Image - Set position and no-repeat

Showing the foundation picture just once is additionally determined by the background-repeat property:

Example

body {
    foundation picture: url("architecture-structures cars.jpg");
    foundation rehash: no-repeat;
}
Try it yourself »

In the precedent over, the foundation picture is appeared in indistinguishable spot from the content. We need to change the situation of the picture, with the goal that it doesn't aggravate the content too much.

The position of the picture is indicated by the background-position property:

Example

body {
    foundation picture: url("architecture-structures cars.jpg");
    foundation rehash: no-repeat;
    foundation position: right top;
}
Try it yourself »

Background Image - Fixed position

To indicate that the foundation picture ought to be settled (won't look with whatever remains of the page), utilize the background-attachment property:

Example

body {
    foundation picture: url("architecture-structures cars.jpg");
    foundation rehash: no-repeat;
    foundation position: right top;
    foundation connection: fixed;
}
Try it yourself »

Background - Shorthand property

To abbreviate the code, it is likewise conceivable to indicate all the foundation properties in one single property. This is known as a shorthand property.

The shorthand property for foundation is background:

Example

body {
    foundation: #ffffff url("architecture-structures cars.jpg") no-rehash right top;
}
Try it yourself »

When utilizing the shorthand property the request of the property estimations is:

  • background-color
  • background-image
  • background-repeat
  • background-attachment
  • background-position

It does not make a difference in the event that one of the property estimations is missing, as long as the different ones are in this order.