我有一個HTML文件,它看起來是這樣的:文本對齊:中心和短期浮動的div
<div style="float:right">
A line of text, floating to the right
</div>
<div style="text-align:center">
And here, several lines of<br />
text which I want to center.
</div>
這使得(至少在Firefox)是這樣的:
And here, several lines of A line of text, floating to the right text which I want to center.
我想要的是第二個div中的文本以單個垂直軸爲中心,不受浮動div高度的影響:
And here, several lines of A line of text, floating to the right text which I want to center.
現在,造成這個問題的原因是我無法更改浮動div;我只用我想要的文字來控制第二個div。此外,我不一定知道浮動div的寬度和高度。我無法使用JavaScript。我不能使用絕對定位,因爲我沒有任何控制父塊的功能,我不知道它們中哪些具有非靜態定位。我真的不想使用表格,除非沒有別的選擇。
有沒有辦法做到這一點?
你能鏈接到演示這個頁面嗎? – 2009-08-16 12:28:20
我自己的示例代碼演示了這一點。只需將示例複製到文本編輯器中,另存爲html文件,然後在瀏覽器中打開。 – tetromino 2009-08-16 12:37:32
你已經發布了所有的CSS?沒有導入的樣式,沒有重置樣式,沒有瀏覽器默認樣式,瀏覽器和/或平臺之間沒有不一致? – 2009-08-16 12:41:41