1

我有一个 1600 像素宽的页面。主要区域虽然只有 900px 宽。我有一个导航应该固定在页面的中心(它是)。我的问题是当我打开页面时,页面是固定的,而不是在打开时居中。当用户访问网站时,我需要做什么才能将所有内容集中在 900px 内?

代码不准确,因为它很详细,但基本上是这样的:http: //jsfiddle.net/wznQk/

<body>
    <div class="container">
        <div class="header">
            <div class="subheader">
                <div class="navigation">
                    <ul>
                        <li>HOME</li>
                        <li>ABOUT</li>
                        <li class="logo"><img src="images/ogsystemslogo.png" /></li>
                        <li>CAREERS</li>
                        <li>CONTACT</li>
                    </ul>
                </div>

                    <div class="undernav">
                        <div class="short">
                            <img src="images/bluemark.png" />
                            <div class="top">TOP OGS NEWS:</div>
                        </div>
                   </div>
            </div>
        </div>
        <div class="content">
        </div>
    </div>
</body>

CSS

.body {
    width: 1600px;
    height: 100%;
    margin: 0 auto;
    padding: 0px;
    border: 0px;
    position: relative;
    text-align: center;
}

.container {
    width: 1600px;
    height: 100%;
    position: relative;
    margin: 0 auto;
    padding: 0px;
    border: 0px;
    text-align: center;
}

.header {
    width: 1600px;
    height: 150px;
    margin: 0 10% 0 10%;
    padding: 0px;
    border: 0px;
    background-color: white;
    position: fixed;
}

.subheader {
    width: 1600px;
    height: 100px;
    margin: 0 auto;
    position: fixed;
    background-color: white;
    top: 0px;
}

.navigation {
    font-family: 'Champagne & Limousines';
    font-size: 20px;
    text-align: left;
    width: 1600px;
    height: 100px;
    padding: 0px;
    margin-left: 0 auto;
    border: 0px;
    list-style: none;
    text-decoration: none;
    display: table-cell;
    vertical-align: middle;
    color: #006699;
    background-color: white;
}

    .navigation ul {
        width: 590px;
        height: 20px;
        list-style: none;
        text-decoration: none;
        position: relative;
        line-height: 55px;
        margin: 0 auto;
        background-color: white;
        padding: 0px;
        border: 0px;

    }

    .navigation ul li {
        width: 70px;
        height: 15px;
        float: left;
        padding-left: 35px;
        background-color: white;
    }
4

2 回答 2

0

请尝试添加此 CSS 而不是您的。在您的 CSS 中,我发现了很多不需要的 CSS 标签,但我保持原样。

body {
    width: 1600px;
    height: 100%;
    margin: 0 auto;
    padding: 0px;
    border: 0px;
    position: relative;
    text-align: center;
}
.container {
    width: 900px;
    height: 100%;
    position: relative;
    margin: 0 auto;
    padding: 0px;
    border: 0px;
    text-align: center;
}
.header {
    width: 1600px;
    height: 150px;
    padding: 0px;
    border: 0px;
    background-color: white;
    position: fixed;
}
.subheader {
    width: 900px;
    height: 100px;
    position: fixed;
    background-color: white;
    top: 0px;
}
.navigation {
    font-family: 'Champagne & Limousines';
    font-size: 20px;
    text-align: left;
    width: 590px;
    height: 100px;
    padding: 0px;
    margin: 0 auto;
    border: 0px;
    list-style: none;
    text-decoration: none;
    vertical-align: middle;
    color: #006699;
    background-color: white;
}
.navigation ul {
    width: auto;
    height: 20px;
    list-style: none;
    text-decoration: none;
    position: relative;
    line-height: 55px;
    background-color: white;
    padding: 0px;
    border: 0px;
}
.navigation ul li {
    width: 70px;
    height: 15px;
    float: left;
    padding-left: 35px;
    background-color: white;
}
于 2013-08-22T09:32:20.247 回答
0

CSS:

.header {
    width: 1600px;
    height: 150px;
    left: 50%;
    margin-left: -800px;/*half of your total width*/
    padding: 0px;
    border: 0px;
    background-color: white;
    position: fixed;
}

添加left: 50%; margin-left: -800px;/*half of your total width*/到您的 .header 类

小提琴:http: //jsfiddle.net/avinvarghese/wznQk/3/show/

于 2013-08-22T10:16:32.567 回答