2013-08-18 27 views
0

我試圖儘可能地複製html中的書的外觀,其中包括左下浮動的下拉帽和正確浮動的多個圖像。一切工作正常,1圖像漂浮右...但是當多於一個圖像右移時,下拉帽改變位置。在我的編輯器中看起來很好,但在我測試過的任何瀏覽器中都沒有。我用盡了一切我能想到的... 的CSS:當圖像浮動時,下拉帽改變位置正確

body { 
background:#9CF; 
margin:0; 
padding:0; 
} 

h1 { 
font-family:Lusitana, serif; 
font-size:14px; 
letter-spacing:.3em; 
} 

h2 { 
font-family:'Crimson Text', serif; 
font-size:12px; 
letter-spacing:.3em; 
font-weight:400; 
} 

p { 
font-family:'Crimson Text', serif; 
font-size:12px; 
line-height:16px; 
font-weight:400; 
margin-top:0; 
color:#000; 
text-align:justify; 
} 

.dropcap { 
font-family:'Crimson Text', serif; 
font-size:310%; 
line-height:65%; 
margin-top:3px; 
margin-right:6px; 
color:#333; 
display:inline-block; 
float:left; 
} 

#container { 
background:#FFF; 
height:698px; 
width:452px; 
padding:30px 30px 40px; 
} 

#imagediva { 
height:229px; 
width:127px; 
background:rgba(200,255,255,0.5); 
margin:0 0 10px 20px; 
} 

#imagedivb { 
height:180px; 
width:268px; 
background:rgba(200,255,255,0.5); 
margin:0 0 10px 20px; 
} 

.floatright { 
clear:right; 
float:right; 
} 

h1.short,h2.short { 
line-height:0; 
} 

的HTML

<div id="container"> 

<div class="floatright" id="imagediva"></div> 
<div class="floatright" id="imagedivb"></div> 

<h1 class="short">First Flight</h1> 
<hr size="1" noshade> 
<h2 class="short">1929</h2> 
<br> 
<p><span class="dropcap">W</span>alter’s first flight experience was in a two seater  open biplane when he was ten years old. His father hired a pilot take Walter and his cousin Victor Azevedo on a flight around the Oakland, CA. airport, the same airport from which Amelia Earhart would begin her ill fated attempt to circumnavigate the globe six years later in 1937. 
</p> 

</div> 

回答

0

入住這Fiddle

提供絕對位置的段落標記,也給它一些寬度。這將解決您的問題。

body { 
background:#9CF; 
margin:0; 
padding:0; 
} 

h1 { 
font-family:Lusitana, serif; 
font-size:14px; 
letter-spacing:.3em; 
} 

h2 { 
font-family:'Crimson Text', serif; 
font-size:12px; 
letter-spacing:.3em; 
font-weight:400; 
} 

p { 
font-family:'Crimson Text', serif; 
font-size:12px; 
line-height:16px; 
font-weight:400; 
margin-top:0; 
color:#000; 
text-align:justify; 
position: absolute; 
width: 300px 
} 

.dropcap { 
font-family:'Crimson Text', serif; 
font-size:310%; 
line-height:65%; 
margin-top:3px; 
margin-right:6px; 
color:#333; 
display:inline-block; 
float:left; 
} 

#container { 
background:#FFF; 
height:698px; 
width:452px; 
padding:30px 30px 40px; 
} 

#imagediva { 
height:229px; 
width:127px; 
background:rgba(200,255,255,0.5); 
margin:0 0 10px 20px; 
} 

#imagedivb { 
height:180px; 
width:268px; 
background:rgba(200,255,255,0.5); 
margin:0 0 10px 20px; 
} 

.floatright { 
clear:right; 
float:right; 
} 

h1.short,h2.short { 
line-height:0; 
} 
+0

我感謝您的回覆維卡斯,但絕對定位不會允許文本換行的圖像周圍,而忽略利潤(每個頁面都包含文本的一整頁,我並沒有包括在該示例中的所有文本爲了簡潔起見)。我錯過了什麼? –

+0

我偶然發現了這個問題的解決方案。通過給第一個paragrah
一類清楚:兩者;所有東西都能正確放置,讓我可以控制圖像的邊距,文本保持在頁面的流程中並且代碼有效。有沒有人看到這個問題,或有更好的解決?我感謝Vikas和其他試圖幫助我的人。 –

+0

其實在進一步檢查時......在頁面上的最後一個段落結束標記上放置一個「清除兩個」類同樣適用。 –