浮动时填充不为0:右

时间:2011-06-23 04:45:32

标签: html css

我正试图让图像一直在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>* { 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/,你会看到红色仍然可以在边框的右侧看到,它应该一直向右浮动。

5 个答案:

答案 0 :(得分:4)

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

余量右:5px的

答案 1 :(得分:4)

取下图片周围margin-right:5px;内的DIV

<div style="float:right;">

答案 2 :(得分:3)

好的浮动有“保证金权利:5px;”在它的style属性中。这导致右边有一个5像素的边距...如果你删除它,它将一直向右移动。

你要求让图像在div上一直向右移动,但你没有说出哪个div。 img 已经在其直接父级的右侧一直,但该div距其父级右侧5个像素(“login”)。

答案 3 :(得分:1)

将图像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>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>

答案 4 :(得分: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