我把它放在一起,許多不同的來源。亞歷克斯科爾斯的解決方案離蝙蝠最近,但中間並沒有居中。它比我的爛攤子還要乾淨得多。我開始與代碼this post:
<style type="text/css">
.leftit {
float: left;
}
.rightit {
float: right;
}
.centerit {
width: 30%;
margin-right: auto;
margin-left: auto;
text-align: center;
}
.centerpage {
width: 80%;
margin-right: auto;
margin-left: auto;
}
</style>
</head>
<body>
<div class="centerpage">
<div class="leftit">Hello Left</div>
<div class="rightit">Hello Right</div>
<div class="centerit">Hello Middle</div>
</div>
(fiddle for above)
我把亞歷克斯清理的元素就是讓我更接近我的目標,但該中心色塊是太寬。從this question我瞭解到「最大寬度」,最終成爲我需要的最後一部分......所以我想。
編輯:最大寬度不能在IE7怪癖模式下工作(我必須支持)所以從this page我學會了如何調整我的CSS以在IE7 quirks模式,IE8和FF中工作。
最後的代碼(fiddle):
.leftit {
float: left;
font-size: 0.8em;
}
.rightit {
float: right;
font-size: 0.8em;
}
.centerit {
width:220px;
margin-right: auto;
margin-left: auto;
font-size: 0.8em;
}
#headmiddle div {
border: 1px solid #000;
margin-bottom: 3px;
}
.centerpage {
margin-right: auto;
margin-left: auto;
text-align: center;
}
strong { font-weight: bold; }
.search { background: orange; }
.active { background: #8ed200; }
dt { float: left; font-weight: bold; }
dd { margin-left: 4.5em; }
<div class="centerpage">
<div class="leftit">a little search form here</div>
<div class="rightit">
<dl>
<dt>Legend:</dt>
<dd>Status numero uno</dd>
<dd>Status two</dd>
</dl>
</div>
<div class="centerit" id="headmiddle">
<div class="active"><strong>Status:</strong>
Active</div>
<div class="search">Search results displayed</div>
</div>
</div>
感謝所有偉大的答案 - 我從這個問題中學到了很多。
Paul
Ha,山寨版! +1進行我們的更改以使其正常工作。 – 2011-06-08 18:25:43