how to cover image in css 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: is there an img cover

body {
  margin: 0;
}
img {
  display: block;
  width: 100vw;
  height: 100vh;
  object-fit: cover;
}

Example 3: how to set background automatically with my screen height

body {

    background-image: url("img_tree.gif");

   background-repeat: no-repeat;   
 background-attachment: fixed;
  
   background-position: top center;
  background-size: contain;

 }

Example 4: css image cover

object-fit: contain;

Tags:

Misc Example