如何使网页居中(在任何分辨率下)?在线急等。。。

maggie123 2007-01-12 02:12:11
我是在1024*768的分辨率下做的网页,在800*600及1280*800的分辨率下显示的网页不是不能全屏就是靠左显示。搜了好多种方法还是不能解决,请大家赐教!
...全文
5352 29 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
29 条回复
切换为时间正序
请发表友善的回复…
发表回复
icemoist 2010-03-05
  • 打赏
  • 举报
回复

最简单的办法是在<body> …… </body>中间加上<center></center>,即有:


<body> <center> …… </center></body>
jaycam 2007-01-12
  • 打赏
  • 举报
回复
margin:auto
ken_flash 2007-01-12
  • 打赏
  • 举报
回复
内容确实应放在tabl,至少3列,然后td的宽度不要使用像素,而使用百分比

这个应该可行的
<table>
<tr>
<td width=10%> </td>
<td>内容</td>
<td width=10%> </td>
</tr>
</table>
maggie123 2007-01-12
  • 打赏
  • 举报
回复
sp1234,你的我也试过了,可还是不行。我一定会补html的课,经理给本书就让做个网站出来,我也是一直在黑暗中摸索着做。
结贴了,虽然问题还未解决。我再去找些资料看看吧,谢谢大家支持了!
  • 打赏
  • 举报
回复
紧凑点更好:

<table width="100%" height="100%" cellpadding=0 cellspacing=0>
lxs5i5j 2007-01-12
  • 打赏
  • 举报
回复
用这个怎么样

<body>
<center>
....(你的页面内容)
</center>
</body>
maggie123 2007-01-12
  • 打赏
  • 举报
回复
mrloulou,我试过了,还是不行???
  • 打赏
  • 举报
回复
唉,“网页居中”结果全都顶部对齐,html还没过关搞asp.net就难度大了。


你的页面:

<%@ Register TagPrefix="uc1" TagName="ControlLeft2" Src="ControlLeft2.ascx" %>
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="MyWeb.WebForm1" smartNavigation="True" description="首页"%>
<html>
<head>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</head>
<body bgcolor="#ffffff" ms_positioning="FlowLayout" leftmargin="0" rightmargin="0"
topmargin="0" bottommargin="0">
<form id="Form1" method="post" runat="server">
<table width="100%" height="100%">
<tr>
<td align="center" valign="middle">
...放你的控件
</td>
</tr>
</table>
</form>
</body>
</html>
maggie123 2007-01-12
  • 打赏
  • 举报
回复
misng(沦落人),我试过了,可是它还是靠左上角显示,我的另一个页面可以居中,但它没有form,代码如下:
...
<BODY >
<DIV align=center>
<asp:Panel id=Panel1 runat="server" Height="100px"></asp:Panel>
<CENTER>
<TABLE height=4 cellSpacing=0 cellPadding=0 width=740 align=center border=0>
<TBODY>
<TR>
<TD>
<P> </P></TD></TR></TBODY></TABLE></CENTER>
...
</BODY>
其他页面,特别是首页的页面较复杂,不能够用同样的方法。。。
用大家的上述方法不知道为什么都不能实现,还有什么方法可以的,或者是否是我上面的代码中有别的问题导致它不能实现的?谢谢!
阿牛138588 2007-01-12
  • 打赏
  • 举报
回复
内容确实应放在tabl,至少3列,然后td的宽度不要使用像素,而使用百分比
mrluoluo 2007-01-12
  • 打赏
  • 举报
回复
把<form id="Form1" style="POSITION: static" method="post" runat="server">
改为
<form id="Form1" method="post" runat="server">
有style="POSITION: static"这个,都去掉,否则没用
然后像上面说的,在最外面加个<body></body>之间,加
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td>
你<body></body>之间的代码
</td>
</tr>
</talbe>
我看你有戏 2007-01-12
  • 打赏
  • 举报
回复


和misng(沦落人)
的观点一样
lxs5i5j 2007-01-12
  • 打赏
  • 举报
回复
我都是这样做的

<body>
<center>
....(你的页面内容)
</center>
</body>
  • 打赏
  • 举报
回复
放在页面中间,如果在顶部,这显然不是中间。
benefactor 2007-01-12
  • 打赏
  • 举报
回复
该给分了吧。。
iuhxq 2007-01-12
  • 打赏
  • 举报
回复
body{
text-align:center;

}
harryjanny 2007-01-12
  • 打赏
  • 举报
回复
ding
misng 2007-01-12
  • 打赏
  • 举报
回复
是这样的。。,刚才多了个table
哪个table是我的主内容。。不好意思。。

<body style="POSITION: static" bgColor="#ffffff" MS_POSITIONING="FlowLayout">

<form id="Form1" style="POSITION: static" method="post" runat="server">
<table width="100%">
<tr>
<td align="center">

...这里是你的内容

</td>
</tr>
</table>


</form>
</body>
maggie123 2007-01-12
  • 打赏
  • 举报
回复
可是为什么试了都不行呢?能不能具体一点,<div>...</div>还有<table>...</table>应该加在什么位置啊?我的网站已经做好了,就差将做好的页面居中了,大家帮忙看一下究竟是什么问题,为什么不能居中呢?!
misng 2007-01-12
  • 打赏
  • 举报
回复
<body style="POSITION: static" bgColor="#ffffff" MS_POSITIONING="FlowLayout">

<form id="Form1" style="POSITION: static" method="post" runat="server">
<table width="100%">
<tr>
<td align="center">
<table cellSpacing="0" width="760" border="0">
<tr>
<td>
...这里是你的内容
</td>
</tr>
</table>
</td>
</tr>
</table>


</form>
</body>
加载更多回复(8)

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧