为什么在ASP.NET文件中,一个div不能填满整个屏幕?

huangapple go评论58阅读模式
英文:

Why can't a div in aspx file fill in whole screen in ASP.net file?

问题

The Code A 是一个 aspx 文件,我希望具有 id="container" 的 div 填满整个屏幕,但我只得到图像 A,并且具有 id="container" 的 div 只有很小的高度,我的代码有什么问题?

Code A

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="aa.aspx.cs" Inherits="LinkTabs.aa" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="Css/Main.css" rel="stylesheet" />
</head>
<body>
    <form id="form1" runat="server">
         <div id="container">
             Hello World!
        </div>

    </form>
</body>
</html>

body {
    background-color: red;
    height: 100%;
    width: 100%;
}


#container {
    height: 100%;
    width: 100%;   
    background-color: blue;
}

Image A
为什么在ASP.NET文件中,一个div不能填满整个屏幕?

英文:

The Code A is a aspx file, I hope that the div with id=&quot;container&quot; fill in whole screen, but I only get Image A, and the div with id=&quot;container&quot; is only a little height, what's wrong with my code?

Code A

&lt;%@ Page Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot; CodeBehind=&quot;aa.aspx.cs&quot; Inherits=&quot;LinkTabs.aa&quot; %&gt;

&lt;!DOCTYPE html&gt;

&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head runat=&quot;server&quot;&gt;
    &lt;title&gt;&lt;/title&gt;
    &lt;link href=&quot;Css/Main.css&quot; rel=&quot;stylesheet&quot; /&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt;
         &lt;div id=&quot;container&quot;&gt;
             Hello World!
        &lt;/div&gt;

    &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;

body {
    background-color: red;
    height: 100%;
    width: 100%;
}


#container {
    height: 100%;
    width: 100%;   
    background-color: blue;
}

Image A
为什么在ASP.NET文件中,一个div不能填满整个屏幕?

答案1

得分: 1

问题在于默认的WebForms中添加的“form”元素。您还需要将其高度设置为100%。并且将“html”的高度也设置为100%,与“body”相同。

<style>
    html, body {
        background-color: red;
        height: 100%;
        width: 100%;
    }

    #container {
        height: 100%;
        width: 100%;
        background-color: blue;
    }

    #form1 {
        height: 100%;
    }
</style>
英文:

The problem is the default WebForms "form" that is added. You need to set that height to 100% also. And set the height of html also to 100%, the same as body.

&lt;style&gt;
     html, body {
        background-color: red;
        height: 100%;
        width: 100%;
    }

    #container {
        height: 100%;
        width: 100%;
        background-color: blue;
    }

    #form1 {
        height: 100%;
    }
&lt;/style&gt;

huangapple
  • 本文由 发表于 2023年3月1日 12:12:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/75599499.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定