簡體   English   中英

使用邊距:0自動,div仍不居中

[英]Using margin: 0 auto, Div still not centered

我試圖將容器div以我的背景為中心,通常我通常都不會遇到任何問題。 我通常只添加css“ margin:0 auto;”。 對於這個網站,我不知道為什么,可能是MIME類型或CSS3或其他內容。但是div不會居中。

這是我的HTML ...

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HEAD>
<TITLE>title</TITLE>
<link rel="stylesheet" type="text/css" href="style.css" />

    <BODY>
        <div class="container">
        </div>
    </BODY>
</HTML>

這是我的CSS ...

body {
    background-image: linear-gradient(left top, #000000 30%, #0000FF 90%);
    background-image: -o-linear-gradient(left top, #000000 30%, #0000FF 90%);
    background-image: -moz-linear-gradient(left top, #000000 30%, #0000FF 90%);
    background-image: -webkit-linear-gradient(left top, #000000 30%, #0000FF 90%);
    background-image: -ms-linear-gradient(left top, #000000 30%, #0000FF 90%);
    background-image: -webkit-gradient(linear, left top, right bottom, color-stop (0.3, #000000), color-stop(0.9, #0000FF));
    height: 100%;
    width: 100%;
    margin: 0;
    width: 0;
}

.container 
{
    margin-left: auto;
    margin-right: auto;
    position: relative;
    width: 940px;
    z-index: 0;
    width: 940px;
    top: -10px;
    height: 80%;
    background-color: #F0F8FF;
    border-radius: 0px 0px 35px 35px; 
    -moz-border-radius: 0px 0px 35px 35px; 
    -webkit-border-radius: 0px 0px 35px 35px; 
    border: 10px solid #696969;
}

並且請忽略我CSS上的糟糕格式。 那不是它在文件中的方式,那只是將其復制過來的錯誤。 我最初測試的瀏覽器也是Chrome。

刪除width: 0; 來自CSS規則中的body ,如下所示:

body {
    background-image: linear-gradient(left top, #000000 30%, #0000FF 90%);
    background-image: -o-linear-gradient(left top, #000000 30%, #0000FF 90%);
    background-image: -moz-linear-gradient(left top, #000000 30%, #0000FF 90%);
    background-image: -webkit-linear-gradient(left top, #000000 30%, #0000FF 90%);
    background-image: -ms-linear-gradient(left top, #000000 30%, #0000FF 90%);
    background-image: -webkit-gradient(linear, left top, right bottom, color-stop (0.3, #000000), color-stop(0.9, #0000FF));
    height: 100%;
    width: 100%;
    margin: 0;
}

您沒有HTML標記來啟動文檔,請確保這可能會導致問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM