html - CSS,垂直对齐在 Mozilla Firefox 中不能正常工作

标签 html css firefox cross-browser vertical-alignment

我正在尝试创建一个具有固定高度页眉和页脚 (=Nav) 的页面,它们之间是一个 contentWrapper div,它完全拉伸(stretch)以填充屏幕的最大高度。在 contentWrapper 中,有一个包含表单的内容 div。我需要此内容 div 根据其父 div contentWrapper 在垂直和水平方向上对齐。我为此找到了一个解决方案,它运行良好,但仅适用于 Chrome 和 IE,不适用于 Firefox(版本 22.0)

我创建了这个 fiddle ,您可以在其中观察这种行为,尝试不同的浏览器。 http://jsfiddle.net/qWYqb/

关于如何为 Mozilla Firefox 解决这个问题有什么想法吗?

HTML:

<div id="pageWrapper">
            <header>
                <div id="logo">
                    Logo
                </div>        
            </header>
            <div id="contentWrapper">
                <div class="valignMiddle">
                    <div id="content">
                        <form>
                            <table>
                                <tbody>
                                    <tr>
                                        <td><label for="fullName">Full Name</label></td>
                                        <td><input id="fullName" type="text" name="fullName" required="required" /></td>
                                    </tr>
                                    <tr>
                                        <td><label for="email">E-mail</label></td>
                                        <td><input id="email" type="email" name="email" required="required" /></td>
                                    </tr>
                                </tbody>
                            </table>
                            <div>
                                <input type="submit" id="submit-go" value="Start Now"/>  
                            </div>                
                        </form>  
                    </div>
                </div>
            </div>
            <nav>    
                <ul>
                    <li><a href="#" class="btn1">Option1</a></li>
                    <li><a href="#" class="btn2">Option2</a></li>
                </ul>
            </nav>
        </div>

CSS

* {
    margin: 0;
    padding: 0;
    outline:none;
}
html, body{
    min-height: 100%;
        margin: 0;
    padding: 0;
}

table
{
    border-collapse: collapse;
    border-spacing: 0;
}

td, th {
    vertical-align:top;
}

body{
    background-color: #E3E3E3;
}
/* This padding is there to stop margin collapsing */
div {
    padding: 1px 0;
}

#pageWrapper{
    position:absolute; top:0; bottom:0; left:0; right:0;
    padding: 126px 0 100px 0;
    margin: 0 auto;
    width: 400px;
    overflow: hidden
}

/* --- HEADER --- */
header{ 
    width: 100%;
    height: 126px;
    margin-top:-126px;
    background: yellow;
}

/* --- MAIN CONTENT --- */
#contentWrapper{
    width: 100%;
    position: static; 
    display: table; 
    overflow: hidden; 
    min-height: 100%;
    background: red;
}

.valignMiddle { 
    position: static; 
    display: table-cell; 
    vertical-align: middle; 
    width: 100%; 
}

#content{
    width: 293px;
    margin: 0 auto;
    background: green;
}

/* --- NAVIGATION --- */
nav {
    width: 100%;
    height: 100px;
    margin-bottom:-100px;
    background: pink;
}

nav li {
    display: inline-block;
    list-style: none outside none;
}

nav ul {
    text-align: center;
}

最佳答案

在这里查看工作演示:Demo

#contentWrapper{
    width: 100%;
    position: static; 
    display: table; 
    overflow: hidden; 
    min-height: 100%;
    height: 100%;
    background: red;
}

这在 Firefox 中运行良好。这是您要找的吗?

关于html - CSS,垂直对齐在 Mozilla Firefox 中不能正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18077035/

相关文章:

html - 创建具有不同大小单元格的表格

html - Unicode 字符对齐

html - 背景图片会影响网站加载速度吗

css - 使用 CSS 定位 SVG 元素

c# - 为什么不在我的网站正文中显示背景图片?

javascript - Firefox 尝试在按 Enter 键时将表单发送到同一页面,但没有在表单标记中定义目标

html - 下拉子菜单显示不正确

html - Firefox 18 奇怪的 Canvas 背景行为

python - 如何在 Python 中动态获取 Firefox 配置文件路径?

html - 尝试使用 r 抓取合并的 Html 表