resize background image css code example

Example 1: how to cover full image in css

body {
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}

Example 2: 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 3: html background image fit to screen

body {
  background-position: center;
  background-repeat: no-repeat;
  background-size: contain;
}

Example 4: css cover

background-size: cover;

Example 5: how to scale a bg image acc to size of div

/* One way */
background-size: cover;

/* Other option */
background-size: contain;

Example 6: how to change the width of a background image in css

#example1 {		/* Example1 has an auto background size */
  background: url(mountain.jpg);
  background-repeat: no-repeat;
  background-size: auto;
}

#example2 {		/* Example2 has an fixed background size */
  background: url(mountain.jpg);
  background-repeat: no-repeat;
  background-size: 300px 100px;
}

Tags:

Misc Example