我有一個液體佈局頁面,它具有正文集的最大和最小寬度(分別爲1260像素和960像素)。我有一個左邊的邊欄,佔據了左邊的25%,內容佔據了屏幕的右邊75%。在內容中,我放置了兩個帶有固定寬度圖片的div容器(300px x 225px),每個容器下面都有一些文字。如何在液體佈局中保持兩個固定寬度div等距
我想要做的是讓這些div盒保持它們自己的靜態寬度(由文本上方圖片的寬度決定的300px),但爲了參數的緣故,可以保留50px inline和總是在中心(除了50px之外),儘管我有他們的瀏覽器(無論是1260或960像素,或其中的某處)。我想這樣做的原因是,如果我使用邊距來分隔它們,它們只能在一個瀏覽器寬度中看起來'居中'(再次,禁止它們之間的50px),並且它們的佈局不流暢。
的jsfiddle:http://jsfiddle.net/fpN5t/1/
請讓我知道如果我不解釋自己很好!
非常感謝你提前。
<div id="content">
<div id="upper-left-box">
<img class="boxed-content-image" src="images/Leaf 300x225px.jpg" alt="" />
<p>Example text example text example text example text example text example text example text example text example text</p>
</div>
<div id="upper-right-box">
<img class="boxed-content-image" src="images/Lens 300x225px.jpg" alt="" />
<p>Example text example text example text example text example text example text example text example text example text</p>
</div>
<h1 class="first-content-heading">Heading 1</h1>
<p>Your text goes here. Your text goes here. Your text goes here. Your text goes here. Your text goes here. Your text goes here. Your text goes here. Your text goes here. Your text goes here. Your text goes here. Your text goes here. Your text goes here. Your text goes here. Your text goes here. Your text goes here. Your text goes here. Your text goes here. Your text goes here. Your text goes here.</p>
<p> </p>
<h2>Heading 2</h2>
<p>Your text goes here. Your text goes here. Your text goes here. Your text goes here. Your text goes here. Your text goes here. Your text goes here. Your text goes here. Your text goes here. Your text goes here.</p>
<p> </p>
<h3>Heading 3</h3>
<p>Your text goes here. Your text goes here. Your text goes here. Your text goes here. Your text goes here.</p>
<p> </p>
</div>
#content { width: 75%; float: left; margin: 0; background: #FFF; } #upper-left-box { width: 300px; margin: 0 auto; position: relative; text-align: center; float: left; } .boxed-content-image { width: 300px; height: 225px; } #upper-right-box { width:300px; margin: 0 auto; position: relative; text-align: center; float: left; } .first-content-heading { clear: both; }
這是極好的感謝你知道嗎,我確實試過把它放在一個盒子裏,但是我有一個百分比的寬度,它不起作用,我可以問爲什麼會這樣嗎?以防萬一你想要獎勵分數的答案!你太多了 – 2013-03-19 07:00:10
百分比是finicky.If你有容器內的div邊框,填充和邊距它將hav e對所述容器的總寬度有影響。您需要提前計算主容器邊框,邊距和邊距佔用的百分比寬度,並調整主容器內的div寬度。不是不可能的,只需要一點數學。 – Lowkase 2013-03-19 12:46:51
啊,我明白了。謝謝! – 2013-03-20 18:37:09