如何设置网页在不同屏幕分辨率下自动对齐?
我正在 ASP.NET 上创建一个项目,分辨率为 1280x800
。我使用的网页宽度 1245px
在我的系统上运行得非常好,但是当我在分辨率 1024x768
上使用该网站时,对齐就会消失浏览器的。我使用的是
宽度 1245px
,在 1280x800
的分辨率下看起来不错。我尝试了这段代码,但它给了我错误。
protected void Page_Load(object sender, EventArgs e)
{
div1.Style.Add(HtmlTextWriterStyle.Width, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width.ToString());
}
它给出的错误是
命名空间中不存在类型或命名空间名称“Windows” “系统”(您是否缺少程序集引用?)`
那么有没有简单的方法来修复它。
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)
{
div1.Style.Add(HtmlTextWriterStyle.Width, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width.ToString());
}
It is giving error that
The type or namespace name 'Windows' does not exist in the namespace
'System' (are you missing an assembly reference?)`
So is there any simple way to fix it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
屏幕分辨率的问题在于,除非您尝试追求圣杯并使用液体布局(a ** 中的痛苦),否则您实际上无法真正本地支持不同的屏幕分辨率。我想你可以使用很多花哨的 javascript,但是......哎呀......维护噩梦......而且它会让你的页面陷入困境。
您应该将网站设置为仅在假定的 1024 x 768 窗口中显示内容,因为这是迄今为止最常见的屏幕尺寸。
实现此目的的一般方法是使用自动边距将 1024x768 的 div 居中,以便其余部分只是额外的空白。
这无法解决内容垂直居中的问题。我更喜欢的一种方法是使用绝对定位,这样居中就不再是一个因素。我可以使用以下 css 将页面设置为拉伸以适应窗口的大小:
这将导致 div 从窗口顶部拉伸到底部。
我喜欢这个解决方案,因为它受到大多数浏览器及其各种版本的支持,甚至可以很好地处理缩放。
The issue with screen resolution is that unless you try to shoot for the holy grail and use liquid layouts (pain in the a**) then you really can't realistically support different screen resolutions natively. I suppose you could use a lot of fancy javascript but ... OUCH ... and maintenance nightmare .. plus it would bog your pages down.
You should just setup your web site to only display content in an assumed window of 1024 x 768 since that is the most common screen size to date.
A general way to accomplish this is to center a div that is 1024x768 using auto margins so that the rest is just extra white space.
This won't solve the issue of vertically centering your content. One approach I prefer is to use absolute positioning so that centering isn't a factor. I can just setup the page to stretch to fit the size of the window by using this css instead:
This will cause the div to strech from the top of the window to the bottom.
I like this solution cause it is support by most browsers and their various versions and even handles pretty well with zooming.