所以我有一个用作背景的图像,它“缩放以填充”框架,这正是我想要的,但是图像没有居中,因此当窗口像手机一样小时,显示的图像只是边缘。这是我使用的代码:
HTML
<div class="Background">
<div>
CSS
.Background {
display: block;
margin-left: auto;
margin-right: auto;
width: 100vw;
height: 100vh;
background-image: url('background.png');
background-size: cover;
}
如果有人能给我一些提示,那就太好了。谢谢
最佳答案
CSS代码
.Background {
display: block;
margin-left: auto;
margin-right: auto;
width: 100vw;
height: 100vh;
background-image: url('background.png');
background-size: cover;
background-position: center;
}
关于html - CSS - 居中图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31202345/