简体   繁体   English

如何从重新定位的浮动div中折叠空白?

[英]How to collapse white space from a repositioned, floated div?

I'm trying to make side notes for site, but if I use absolute positioning, when two citations are too close to each other, they will overlap. 我正在尝试为站点做旁注,但是如果我使用absolute定位,则当两个引文彼此太近时,它们将重叠。 Using relative positioning, pushing the side note into the sidebar area of the page leaves white space behind, forcing the paragraph's text to wrap around the white space; 通过relative定位,将边注推入页面的侧边栏区域,在后面留出空白,迫使段落文本环绕在空白处; is there a way to collapse that white space using JavaScript? 有没有办法使用JavaScript折叠空白?

Or is there a different/better way to get the same effect using JavaScript? 还是有其他/更好的方法来使用JavaScript获得相同的效果?

It is crucial that the side notes are alongside the citation -- not hidden and shown with JavaScript individually or simply listed separately like footnotes would be. 至关重要的是,旁注必须与引文并排--不能单独使用JavaScript隐藏或显示,也不能像脚注那样单独列出。 And simply avoiding having citations that are too close is not an option. 而且,仅避免避免引用过于接近是不可行的。

Fiddle 小提琴

HTML: HTML:

<div id="main_column" class="grid_3 alpha omega">
    <p class="bodycopy">Donec ultricies massa vel dui lobortis, et ornare augue volutpat. Proin aliquam nec orci ut consequat. Donec sapien libero, tincidunt quis arcu vitae, hendrerit commodo neque.<sup>1</sup><small><strong>1</strong> Side note test. In imperdiet nibh turpis,
    eu scelerisque nisi sagittis eu. Fusce lectus tellus, pretium in venenatis eget, faucibus ac 
    eros.</small> In imperdiet nibh turpis, eu scelerisque nisi sagittis eu. Fusce lectus tellus, pretium in venenatis eget, faucibus ac eros.<sup>2</sup><small><strong>2</strong> Side note 
    test. In imperdiet nibh turpis, eu scelerisque nisi sagittis eu. Fusce lectus tellus, pretium 
    in venenatis eget, faucibus ac eros.</small> Phasellus nec efficitur magna.…</p>
</div>

And the relevant CSS: 以及相关的CSS:

small {
    position: absolute;
    display: block;
    font-size: 14px;
    font-family: BrandonGrotesque, Helvetica, Verdana, Arial, sans-serif;
    top: auto;
    margin-top: -28px;
    margin-left: 640px;
    width: 260px;
    height: auto;
}

Your requirements are tough. 您的要求很严格。 For example - what will you do if you have two citations that occur on the same line? 例如-如果在同一行上出现两个引用,您将怎么办?

There might be a javascript solution to calculate the position of things and move them to an appropriate spot. 可能会有一个javascript解决方案来计算事物的位置并将其移动到适当的位置。 I know that it's possible but I'm not the right guy to clearly write or explain it. 我知道这是有可能的,但我不是正确编写或解释它的合适人选。

I think you can reduce the cases where you might have to compromise with smaller text and line-height: 我认为您可以减少可能不得不以较小的文本和行高折衷的情况:

small {
    font-size: 12px;
    line-height:110%
}

That would make them overlap less often, but to really do this right you need to figure out what you will do when two citations are on the same line. 这会使它们重叠的频率降低,但是要真正做到这一点,您需要弄清楚当两个引用同时出现时将要做什么。 Aside from some kind of css hover/hide effect I think the only way is with some non-trivial javascript figuring out where to put things. 除了某种css悬停/隐藏效果之外,我认为唯一的方法是使用一些平凡的javascript找出放置位置。

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

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