2011-06-23 37 views
0

我試圖使圖像一路向右一個DIV,但它不是發生了什麼:\填充上浮動不爲0:右

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 

<head> 
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> 
<style>* { margin:0;padding:0; } 
#login { 
background:red; 
width:200px; 
xpadding:5px; 
} 
#login a, #login a:visited { 
color:blue; 
text-decoration:none; 
font:12px verdana; 
} 
</style> 
    <title>Untitled 1</title> 
</head> 

<body> 



<div id="login"><div style="float:right;margin-right:5px;"><img src="https://si0.twimg.com/sticky/default_profile_images/default_profile_0_normal.png" /> </div> 

<div style="float:right;color:red;text-align:right;"><a href="#">@Testing</a><br /><a href="?wipe=1">Logout</a></div> 
<div style="clear:both;"></div></div> 

</body> 
</html> 

試穿的說... http://htmledit.squarefree.com/這一點,你當邊框右邊應該浮動時,會看到紅色仍然可見。

+0

我不正好得到你所需要的,這裏我想代碼不正是它應該做的。一切都在'登錄'div裏面,而div是200px,所以一切都在200px寬度內。 'float:right'已經將它浮動到div的最右邊部分 – Balanivash

+0

remove margin-right:5px; –

回答

4

<div style="float:right,margin-right:5px;">

保證金右:5px的

+0

+1,即使它與我的答案競爭。我最喜歡這個答案的措辭。 – mgiuca

+0

給你們三個人+1,首先給出正確的答案。我必須玩弄它才能找到它。 –

+0

我很愚蠢。謝謝。 – nn2

3

那麼漂浮有「margin-right:5px;」在其風格屬性中。這會在右側產生5像素的邊距......如果您將其刪除,則會一直移動到右側。

您要求將圖像一直放在div上的右側,但您沒有說出哪個div。 img 已經是一直到其直接父級的右側,但該div距其父級(「登錄」)右側5個像素。

+0

+1說明 – djlumley

+0

@mu太短Lol,沒有體會到體育道德是一個徽章。我應該更頻繁地這樣做;) – mgiuca

4

脫下你的內心DIV圖像周圍的margin-right:5px;

<div style="float:right;">

1

設置餘量爲0,你的形象DIV中獲取圖像一路之上。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 

<head> 
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> 
<style>body { margin:0;padding:0; } 
#login { 
background:red; 
width:200px; 
xpadding:5px; 
} 
#login a, #login a:visited { 
color:blue; 
text-decoration:none; 
font:12px verdana; 
} 
</style> 
    <title>Untitled 1</title> 
</head> 

<body> 



<div id="login"><div style="float:right;margin-right:0px;"><img src="https://si0.twimg.com/sticky/default_profile_images/default_profile_0_normal.png" /> </div> 

<div style="float:right;color:red;text-align:right;"><a href="#">@Testing</a><br /><a href="?wipe=1">Logout</a></div> 
<div style="clear:both;"></div></div> 

</body> 
</html> 
1

做這樣的:

<div id="login"><div style="float:right;padding-left:10px;"><img src="https://si0.twimg.com/sticky/default_profile_images/default_profile_0_normal.png" /> </div> 

enter image description here