2011-06-20 44 views
0

我正在制作一个网站,并且我有一个母版页。我已经在母版页中设置了元素的宽度和高度,以适应Firefox浏览器,所以当我打开我的页面时它工作正常,但只要我转移到Chrome或Opera或IE,页面不适合整个浏览器区域。该页面比浏览器的可视区域更小(显示空格)或更大(滚动条),功能显而易见,因为我已经对宽度和高度进行了硬编码以适合Firefox。我也知道,当我在Firefox中打开相同的页面但在别人的电脑中时,至少会出现一些失真(由于不同的分辨率)。如何在asp.net中设置元素的大小与浏览器的大小相同

有没有人有一个javascript/c#代码,我可以用它来动态地设置一个元素的大小,作为它打开的浏览器?以下是我的母版页的html。我已经突出显示了我为Firefox设置的粗体代码。

 
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head id="Head1" runat="server"> 
    <title>Untitled Page</title> 
    <asp:ContentPlaceHolder id="head" runat="server"> 
    </asp:ContentPlaceHolder> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
    <table width="1330" cellspacing="1" cellpadding="1" border="0" align="left"> 
    <tr> 
     <td width="5" rowspan=2>&nbsp;</td> 
     <td width="95">&nbsp;</td> 
     <td align="center" width="1230"><img src="Images/dset01titleds.gif" width=392 height=63 border=0 alt="Blank Title w/ Drop Shadow"></td> 
    </tr> 
    <tr> 
     <td align="center" valign="top" width="100"> 
      <a href="http://"><img src="Images/dset01b01.gif" width=114 height=30 border=0 alt="Home"></a><br> 
      <a href="http://"><img src="Images/dset01b02.gif" width=114 height=30 border=0 alt="About Us"></a><br> 
      <a href="http://"><img src="Images/dset01b03.gif" width=114 height=30 border=0 alt="Products"></a><br> 
      <a href="http://"><img src="Images/dset01b04.gif" width=114 height=30 border=0 alt="Services"></a><br> 
      <a href="http://"><img src="Images/dset01b05.gif" width=114 height=30 border=0 alt="Order"></a><br> 
      <a href="http://"><img src="Images/dset01b06.gif" width=114 height=30 border=0 alt="Contact"></a><br> 
      <a href="http://"><img src="Images/dset01b07blank.gif" width=114 height=30 border=0 alt="Blank"></a><br> 
     </td> 
     <td valign="top" width="1230px" style="height:440px"> 
      <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server"> 
      </asp:ContentPlaceHolder> 
     </td> 
    </tr> 
    <tr style="height:10px"><td colspan=3 align=center>bottom of the screen</td></tr> 
    </table> 
    </div> 
    </form> 
</body> 
</html>

回答

0

你为什么不使用CSS风格你的客户区?

你可以使用

width: 100%; 
height: 100%; 

获得元素使用所有可用空间。我不认为它是一个好主意,在c#中计算服务器端的大小。

+0

我知道为此添加服务器端代码并​​不是一个好主意,但为了它而添加了它。至于宽度和高度= 100%,我试过了,但它没有工作,但会再试一次。但是JavaScript会创造奇迹。 – samar

+0

当然,您必须对每个元素应用100%身体 - 格 - 表 - tr等... –

+0

好吧,会试试这个.. !! – samar

0

一般而言,您应该在percentpixel中设置主容器的宽度(Div or table)。当您将其设置为百分之100(100%)时,它将覆盖每个浏览器中的所有页面。 如果将像素设置为主容器,则920像素大致为好。 但您应该使用margin:0px auto css属性将您的容器放置在页面中心。 为您的内部元素,您可以使用百分比和像素。因为你之前已经设置了主容器width

相关问题