【发布时间】:2017-01-22 12:00:05
【问题描述】:
我正在尝试使用宽 x 高为 1024px x 768px 的背景图像创建一个 Div。它必须适合整个浏览器窗口。
使用下面的 css 我可以实现全屏图像,但图像被裁剪
html, body {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
#wrapper {
background-image : url(home.jpg);
background-position: top center !important;
background-repeat: no-repeat !important;
background-size: cover;
background-position: center;
min-height: 100%;
width : 100%;
height : 100%;
}
#container {
height: 100%;
}
我尝试使用@media 选项使用下面的 CSS 设置宽度和高度,但现在我获得了带有滚动条的完整图像,并且空白表示图像未占据全屏。
html, body {
height: 768px;
width: 1024px;
margin: 0;
padding: 0;
}
#wrapper {
background-image : url(home.jpg);
background-position: top center !important;
background-repeat: no-repeat !important;
background-size: cover;
background-position: center;
height: 768px;
width: 1024px;
}
#container {
height: 100%;
}
@media (min-width:769px) and (max-width:1024px){
// your code
}
有人可以指导我如何完成它并且它必须在所有浏览器中工作:(
【问题讨论】: