我可以水平對齊div,所有內容看起來不錯。 尋找垂直對齊不包含任何表的div。 我試圖設置邊距位置的一些負值#容器 內,但那種工作。我知道CSS不支持這個呢?垂直對齊div(無表)
這裏是我的標記:
body
{
background: #777; /* gray */
text-align: center;
}
#container
{
margin: 0 auto;
width: 968px;
text-align: left;
}
#toptab
{
background: #f77; /* red */
height: 14px;
width: 968px;
}
#middletab
{
background: #7f7; /* green */
width: 968px;
}
#data
{
width: 948px; /* 948 for the box plus we need 20 more px to handle the padding */
padding-left: 10px;
padding-right 10px;
}
#bottomtab
{
background: #77f; /* blue */
height: 14px;
width: 968px;
}
<div id="container">
<div id="toptab"></div>
<div id="middletab">
<div id="data">
The quick brown fox jumped over the big red bear.
The quick brown fox jumped over the big red bear.
The quick brown fox jumped over the big red bear.
The quick brown fox jumped over the big red bear.
The quick brown fox jumped over the big red bear.
The quick brown fox jumped over the big red bear.
The quick brown fox jumped over the big red bear.
The quick brown fox jumped over the big red bear.
The quick brown fox jumped over the big red bear.
The quick brown fox jumped over the big red bear.
The quick brown fox jumped over the big red bear.
The quick brown fox jumped over the big red bear.
</div>
</div>
<div id="bottomtab"></div>
</div>
運行上面的代碼片斷,然後單擊 「整頁」,看它目前的樣子。 基本上,它看起來水平很好,但現在我需要它也垂直居中在頁面中。
我想要垂直對齊的元素是#container div。這種效果會迫使整個div和所有的子div不僅要水平對齊,還要垂直對齊。我知道這是可能的,我知道安迪巴德發佈了這樣的解決方案,但它似乎並沒有爲我工作。
你的意思是垂直分佈/對齊或只是圍繞什麼在垂直顯示頁? – 2009-12-15 19:28:48
@Eric最終結果是內容的圓形框應位於頁面中間。截至目前,您看到的內容是居中,但只集中在頂部。我需要將其直接居中在頁面中間。 – JonH 2009-12-15 19:31:27
據我所見,你必須做一些JavaScript,除非你想要一個固定高度的頁面,我懷疑。 – 2009-12-15 19:55:04