我通过将许多不同的来源放在一起得到它。亚历克斯科尔斯的解决方案是最接近蝙蝠的,但中间没有居中。它也比我的烂摊子干净得多。我从这篇文章的代码开始:
<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>
(上面的小提琴)
我采用了 Alex 清理的元素,这让我更接近我的目标,但中心色块太宽了。从这个问题中我了解了“最大宽度”,它最终成为我需要的最后一块……或者我是这么想的。
编辑: max-width 在 IE7 quirks 模式下不起作用(我必须支持)所以从这个页面我学会了如何调整我的 css 以在 IE7 quirks 模式、IE8 和 FF 下工作。
最终代码(小提琴):
.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>
感谢所有出色的答案 - 我从这个问题中学到了很多东西。
保罗