简体   繁体   English

消除右下浮动的空白

[英]Eliminating white space under a division floated to the right

I'm trying to eliminate white space below a division which I am floating to the right. 我试图消除浮动在右侧的分隔线下方的空白。

My intent is to define a division which I can place anywhere on a page and have it float to the right. 我的意图是定义一个分区,我可以将其放置在页面上的任何位置,并将其浮动到右侧。 A button will expand the division - increase it's height and width - to allow the division to be read. 一个按钮将扩展分区-增加分区的高度和宽度-以便读取分区。 I've left out all of that processing to simplify the examples. 我省略了所有处理以简化示例。

I've got it floating right - - it was simple to do, just code float: right; 我已经把它浮动了--很容易做到,只是代码float:right; using CSS. 使用CSS。 The problem is that if I do not specify a height for the division, I get extra white space below the division. 问题是,如果我没有为分隔指定高度,则在分隔下方会得到多余的空白。 If I set the height so that there is no white space under the division, the button extends below the division's border. 如果我将高度设置为在分隔线下没有空白,则按钮会延伸到分隔线的边界下方。

Go to http://www.bobnovell.com/sideboxproblem.html for a page with examples. 访问http://www.bobnovell.com/sideboxproblem.html以获得带有示例的页面。

Bob 鲍勃

You got the space, because the div with floating right is more height than one line of text. 您获得了空间,因为具有浮动右边的div高度比一行文本要高。 So it takes two lines. 因此需要两行。

If the div should stay on his on line, wrap the text in a new div and set clear=both on it. 如果div应该保持在线,则将文本换成新的div并在其上设置clear=both

Here is an example: http://jsbin.com/hujax/1/ 这是一个示例: http : //jsbin.com/hujax/1/

Update follow the conversation in comments: 更新评论中的对话内容:

If you do not want change the markup, you could use position:ablsolute on your div and position it with top:1em (or what ever you want) and right:0 . 如果您不想更改标记,则可以在div上使用position:ablsolute并将其与top:1em (或您想要的任何东西)和right:0 Also the container of the text and headline need the style: position:relative . 文本和标题的容器也需要样式: position:relative

here is and example: http://jsbin.com/hujax/4/ 这是示例: http : //jsbin.com/hujax/4/

update 更新

with negative margin-bottom you can reduce the needed height of your div . margin-bottom负,则可以降低div的所需高度。

http://jsbin.com/hujax/3/ http://jsbin.com/hujax/3/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM