background image best size code example

Example 1: background image size css

#example1 {
  background: url(mountain.jpg);
  background-repeat: no-repeat;
  background-size: auto;
}

#example2 {
  background: url(mountain.jpg);
  background-repeat: no-repeat;
  background-size: 300px 100px;
}

Example 2: make backgrond image smaller

/*The cover value specifies that the background image should be sized
so that it is as small as possible while ensuring that both dimensions
are greater than or equal to the corresponding size of the container.*/

background-size: cover;

Tags:

Css Example