background-size: cover
属性可以让图片占据整个屏幕,但它会保持图片的纵横比例,因此在大屏幕上只能看到部分图片。如何让图片不受纵横比例的限制,让图片占据整个屏幕并显示完整的图片呢?
HTML:
<html>
<head>
<link href="styles.css" rel=stylesheet>
<title>
Enjoy ;)
</title>
</head> <script type="text/javascript" src="getBG.js"></script></head>
<body>
<div class="intro">
<div class="textbg">
<div class="introText">
Welcome to PicShare
</div>
<div class="introDesc">
Today's theme is
</div>
</div>
</div>
<div class="back"> </div>
<div class="bg1" onclick="genBg()"><script>genBg()</script></div>
</body>
</html>
CSS:
html{
margin: 0px;
height: 100%;
}
body{
height: 100%;
margin: 0px;
background-color: #424242;
}
.intro{ //want this background to take up entire screen
height:100%;
background-color: #424242;
background-image: url("assets/themes/theme1.jpg");
background-repeat: no-repeat;
background-size: cover;
}