英文:
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;
}
英文:
The Code A is a aspx file, I hope that the div with id="container"
fill in whole screen, but I only get Image A, and the div with id="container"
is only a little height, what's wrong with my code?
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;
}
答案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
.
<style>
html, body {
background-color: red;
height: 100%;
width: 100%;
}
#container {
height: 100%;
width: 100%;
background-color: blue;
}
#form1 {
height: 100%;
}
</style>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论