本文介绍了我的元素没有填满页面的整个空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,使用下面的CSS代码,我希望页面完全被计算机上的图像填充。相反,结果是这样的:

So using the CSS code below I wanted to make my page fill entirely with an image located on my computer. Instead, it turned out like this:

#background {
    background-image: url("anFtp");
    position: fixed;
    height:100%;
    width:100%;
    z-index: -1;
    float: left;
}

您可能会看到页面的顶部和左侧都有空白。现在,我已经尝试了多种方法,这就是我的代码现在的样子。原始代码如下:

As you can probably see there is white space located on the top and left of the page. Now I have tried multiple things, this is just what my code looks like now. The original code looked like:

#background {
    background-image: url("anFtp");
    position: fixed;
    width: 1600px;
    height: 900px;
    z-index: -1;
}

有多个结果,我已经尝试过(更改 1600px 900px 100%),但其中大多数告诉我别人写的东西是不正确的,不是代码或作者知识的实际错误。

There are multiple results for this and I have tried them (changing 1600px and 900px to 100%) but most of them tell me that something someone else wrote was incorrect, not an actual error of the code or the knowledge of the writer.

编辑/添加以下答案

添加以下答案建议可以解决此问题,但现在看起来像这样:

adding what the below answer suggested helped the problem but now it looks like this:

推荐答案

尝试一下。它有效吗

body {margin: 0;}

编辑:对于更新的问题

#background {
    background: url(images/bg.jpg) no-repeat center center fixed;
    background-size: cover;
}

这篇关于我的元素没有填满页面的整个空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 06:59