为什么即使设置了指定的宽度,边距0自动也不会居中?

时间:2018-12-09 21:58:58

标签: html css

我的页面没有居中,我尝试使用width: 980px;作为搜索来修复页面不居中的问题,只是声明容器/包装的大小。

我应该提到,我使用的是Web Expression 4中的DWT(动态Web模板)。

身体:

<body>

    <div id="wrapper">

        <div>

            <div id="bannerTop" style="position: absolute; width: 980px; height: 10px; z-index: 3; left: 0px; top: 0px" class="auto-style1">
            </div>
            <div id="banner" style="position: absolute; width: 980px; left: 0px; top: 17px; height: 100px; z-index: 1">
                <img alt="Remax Logo" height="97" src="images/remax_logo.png" width="519"></div>
        </div>



        <div id="topNav" style="position: absolute; width: 980px; height: 50px; z-index: 2; left: 0px; top: 117px">

            <ul>
                <li><a href="index.html">Home</a></li>
                <li><a href="switchboard.html">Switchboard</a></li>
                <li><a href="properties.html">Property Page</a></li>
                <li><a href="contact.html">Contact Us</a></li>
                <li><a href="credits.html">Sitemap / Credits</a></li>
            </ul>
        </div>

        <div id="sideNav">

        </div>

        <!-- #BeginEditable "content" -->
        <div id="content" style="position: absolute; width: 777px; height: 563px; z-index: 5; left: 215px; top: 209px">
        </div>
        <!-- #EndEditable -->


        <div id="footerNav" style="position: absolute; width: 995px; height: 49px; z-index: 6; left: 0px; top: 773px">
            <ul>
                <li><a href="index.html">Home</a></li>
                <li><a href="switchboard.html">Switchboard</a></li>
                <li><a href="properties.html">Property Page</a></li>
                <li><a href="contact.html">Contact Us</a></li>
                <li><a href="credits.html">Sitemap / Credits</a></li>

            </ul>
        </div>

    </div>

</body>

CSS:

body{
    font-family: Arial, Helvetica, sans-serif;
    background-color: #F2F2F2;

}
#wrapper{
    width: 980px;
    margin: 0 auto;
    background-color: #FFFFFF;

}

1 个答案:

答案 0 :(得分:4)

定位问题:

#wrapper{
    width: 980px;
    margin: 0 auto;
    background-color: #FFFFFF;
    position: relative; /* this fixes it */
}