如何居中< div>元素 [英] How to center a <div> element in IE6

查看:123
本文介绍了如何居中< div>元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用一个单独的div部分实现对话框样式行为,其中包含所有内容。

trying to implement a dialog-box style behaviour using a separate div section with all the stuff inside it.

当需要显示对话框它必须显示在WINDOW的中心,而不是在页面的中心,即,REGARDLESS的scroling位置。此外,如果用户滚动页面,正确的解决方案将不会移动对话框。

When the "dialog box" needs to be shown, it has to display at the center of the WINDOW, not in the center of the page, that is, REGARDLESS of the scroling position. Furthermore, the correct solution will not move the "dialog box" if the user scrolls the page.

在Chrome和FF中,使用position ='fixed' div。直接的方式。

In Chrome and FF this works using position='fixed' and centering the div in the intuitive way.

这似乎不工作在IE6(显然固定不支持那里)。

This does not seem to work in IE6 (apparently fixed is not supported there).

任何想法?

推荐答案

如果我是你,它使用jQuery和我建议你尝试它。这应该完全适合基于jQuery的解决方案[jQuery版本] [1]或尝试

If I were you I would do it using jQuery and I would suggest you try it out too. This should fit perfectly for jQuery based solution [jQuery Version][1] or try out

body { 
    font: 80% verdana, arial, helvetica, sans-serif;        
    text-align: center; /* for IE */    
}   

#container {        
    margin: 0 auto;   /* align for good browsers */         
    text-align: left; /* counter the body center */
    border: 2px solid #000;         
    width: 80%;     
}

这篇关于如何居中< div>元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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