medivh
0
Q:

how to fit background image in html

body {
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}
1
body {
  background-position: center;
  background-repeat: no-repeat;
  background-size: contain;
}
2
html { 
  background: url(images/bg.jpg) no-repeat center center fixed; 
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}
0
 /* To make an Image fit the Screen*/


METHOD - 1

html { 
  background: url(images/yourImage.jpg) no-repeat center center fixed; 
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}

METHOD - 2

IMP: To make sure that the image covers the whole screen, 
you must apply **height: 100%** to both <html> and <body>:

body, html {
  height: 100%;
}
1
<head>
<style>
#example1{
  border: 2px solid black;
  padding: 100px;
  background: url(mountain.jpg);
  background-repeat: no-repeat;
  background-size: 100% 100%;
}
</style>
</head>
<body>
<div id="example1">
</div>
</body>
0

New to Communities?

Join the community