如何自动设置不同屏幕分辨率的网页对齐方式? [英] How to set the alignment of the web page on different screen resolution automatically?

查看:101
本文介绍了如何自动设置不同屏幕分辨率的网页对齐方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个关于ASP.NET的项目,而我的分辨率是1280x800。我正在使用网页1245px的宽度,这在我的系统上运行得非常好但是当我在1024x768分辨率上使用该网站时,对齐就不在浏览器中了。我正在使用< div>宽度1245px这对1280x800的分辨率看起来不错。

我尝试了这段代码,但它给了我错误。







I'm making a project on ASP.NET and I've the resolution 1280x800. I'm using the width of the web page 1245px which is running very fine on my system but when I'm using the site on the resolution 1024x768 then the alignment goes out of the browser. I'm using <div> width 1245px which is looking nice on the resolution of the 1280x800.
I tried this code but it is giving me error.



protected void Page_Load(object sender, EventArgs e)<br />
    {<br />
        div1.Style.Add(HtmlTextWriterStyle.Width, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width.ToString());<br />
    }



给出错误



名称空间'System'中不存在类型或命名空间名称'Windows'(是你吗?缺少程序集引用?)`



我知道这段代码是针对windows表单的。那么有什么简单的方法来解决它吗?有没有办法通过获得系统分辨率来设置分辨率并根据它进行调整?

我已经将


It is giving error that

The type or namespace name 'Windows' does not exist in the namespace 'System' (are you missing an assembly reference?)`

I know that this code is for the windows form. So is there any simple way to fix it? Is there a way to set the resolution through getting the system resolution and adjust it according to that?
I've set the width of the

的宽度和一些表设置为1245px如何处理它们case?
and some tables to 1245px how to handle them in that case?

推荐答案

你得到了这个错误,因为你试图在你的asp.net中使用一个窗体表格意味着web表单应用程序..



并为您的解决方案尝试使用javascript获取您的屏幕分辨率

像这样...



You got that error because you are trying to use a windows form in side your asp.net means web form application..

and for your solution try to get your screen resolution using javascript
like this...

<script type="text/javascript">
    function detecteScreenResolutions() {
        var width = screen.width;
        var height = screen.height;
        alert("YOUR SCREEN RESOLUTION IS "+width +" x "+height);
    }
</script>





并根据此功能结果设置你的div的css类..



and as per this functin result set your css classes of your div..


protected void Page_Load(object sender, EventArgs e)
        {
            Response.Write(" <script language='JavaScript'> window.moveTo(0,0); window.resizeTo(screen.width,screen.height); </script>");
        }


这篇关于如何自动设置不同屏幕分辨率的网页对齐方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆