Html CSS自动生成中的背景图像

Html CSS自动生成中的背景图像,html,css,asp.net,Html,Css,Asp.net,我有一个数据库的背景图像和文字的标题。我还有一个gridview,它也连接在数据库中 代码: CSS: 我这里的问题是,背景图像取决于Gridview的高度或数据。我希望它像一个背景图像,它将填补所有的浏览器 有办法吗?我不喜欢固定宽度和高度。我希望它能自动填满。。。我已经尝试过宽度和高度将变为“自动”和“100%”,但它不起作用。HTML代码: HTML Code: <body id="Body"> <div id="BgImage"> <

我有一个数据库的背景图像和文字的标题。我还有一个gridview,它也连接在数据库中

代码:

CSS:

我这里的问题是,背景图像取决于Gridview的高度或数据。我希望它像一个背景图像,它将填补所有的浏览器

有办法吗?我不喜欢固定宽度和高度。我希望它能自动填满。。。我已经尝试过宽度和高度将变为“自动”和“100%”,但它不起作用。

HTML代码:
HTML Code:
<body id="Body">
    <div id="BgImage">
        <asp:Label ID="Emp_Channel" runat="server" Font-Bold="True" Font-Size="XX-Large"></asp:Label>
        <asp:GridView>
    </div>
</body>

CodeBehind Code:
//Bgimage.Attributes.Add("Style", "background-repeat:no-repeat; background-image: url(" + _bgimg + ");");
Body.Attributes.Add("Style", "background-image: url(" + _bgimg + ");");

CSS Code:
body {
    background-size: 100% 100%;
    background-repeat: no-repeat;
    margin: 0;
    padding: 0;
}
代码隐藏代码: //添加(“样式”,“背景重复:无重复;背景图像:url”(“+\u bgimg+”);”); 添加(“样式”,“背景图像:url”(“++bgimg+”);”); CSS代码: 身体{ 背景大小:100%100%; 背景重复:无重复; 保证金:0; 填充:0; }
也许可以试试

 body{
      background: url(yourimage) fixed center center;
      background-size: contain;
      background-repeat:no-repeat;
      }

使用以下css样式进行尝试

#BgImage
{
    width:100%;
    height:100%;
    position:absolute;
    background-repeat: no-repeat;
    margin: 0;
    padding: 0;
}

我解决了我的问题

user1437687的注释是正确的,而我只是更改了css代码

HTML Code:
<body id="Body">
    <div id="BgImage">
        <asp:Label ID="Emp_Channel" runat="server" Font-Bold="True" Font-Size="XX-Large"></asp:Label>
        <asp:GridView>
    </div>
</body>

CodeBehind Code:
//Bgimage.Attributes.Add("Style", "background-repeat:no-repeat; background-image: url(" + _bgimg + ");");
Body.Attributes.Add("Style", "background-image: url(" + _bgimg + ");");

CSS Code:
body {
    background-size: 100% 100%;
    background-repeat: no-repeat;
    margin: 0;
    padding: 0;
}

它起作用了。。但它仍然取决于GridViews的高度如果添加背景大小会发生什么:contain@mjroodt..只是一个小图像。。我只是将标签放在图像标签中,而不是放在主体中,因为图像来自database@user1437687... 它仍然取决于网格视图的高度。。我已经复制并粘贴了你给我的代码。到目前为止,高度只是我们的问题…@mjroodt…也不起作用。背景图像来自数据库,这就是为什么我在codebehind中调用背景图像
 body{
      background: url(yourimage) fixed center center;
      background-size: contain;
      background-repeat:no-repeat;
      }
#BgImage
{
    width:100%;
    height:100%;
    position:absolute;
    background-repeat: no-repeat;
    margin: 0;
    padding: 0;
}
HTML Code:
<body id="Body">
    <div id="BgImage">
        <asp:Label ID="Emp_Channel" runat="server" Font-Bold="True" Font-Size="XX-Large"></asp:Label>
        <asp:GridView>
    </div>
</body>

CodeBehind Code:
//Bgimage.Attributes.Add("Style", "background-repeat:no-repeat; background-image: url(" + _bgimg + ");");
Body.Attributes.Add("Style", "background-image: url(" + _bgimg + ");");

CSS Code:
body {
    background-size: 100% 100%;
    background-repeat: no-repeat;
    margin: 0;
    padding: 0;
}
body {
        -webkit-background-size: cover;
        -moz-background-size: cover;
        -o-background-size: cover;
        background-size: cover;
        background-repeat: no-repeat;
        margin: 0;
        padding: 0;
    }