内联元素导致文本停止换行?这么简单?

发布于 2024-12-13 04:24:08 字数 1663 浏览 3 评论 0原文

http://jsfiddle.net/nicktheandroid/SsfpG/

我不明白为什么这些内联元素是导致段落停止换行,或者未完成在内联元素之前放置文本,换句话说:某些内容导致 DIV 设置为 display:inline-block 之前的换行符,甚至如果我只需将其设置为 display:inline 即可。如果我将 DIV 更改为 SPAN,那么它就可以工作,但是如果我将 DIV 设置为 display:inlinedisplay:inline-block 那么它应该像这样工作一个SPAN..这应该非常简单!啊啊!

CSS

p {
    position:relative;
}

.trigger {
    display:inline-block;
    position:relative; 
}

.toolTip {
    display:none;
    position:absolute;
    top:0;
    left:0;

}

.triangle {
    display:inline;
    position:absolute;
    top:0;
    left:0;
}

HTML

<p>
    Hello this is an example paragraph and I love to talk about typography
    here on somewhere in between the this and now when I see all of the
    dogs running around the streets I'm like oh my goodness puppy what are
    you doing to the cats when  

    <div class="trigger">TRIGGER TRIGGER
        <div class="toolTip">
            This part is hidden right now, this will be the tooltip, for testing
            purposes it is hidden.
            <div class="triangle"></div>
        </div>
    </div>

    in that one movie and i'm
    like oh wow this is insane i dont know what to even think when I see
    all of the cats gone, okay i'm gonna stop now mr person there. I'm like 
    oh my goodness puppy what are
    you doing to the cats when you see them, now they're all vanished
    since you came to town puppy
</p>    

http://jsfiddle.net/nicktheandroid/SsfpG/

I don't understand why these inline elements are causing the paragraph to stop wrapping, or, to not finish placing text before the inline element, in other words: something is causing a line-break just before the DIV set to display:inline-block, even if i just set it to display:inline. If I change the DIV's to SPAN's, then it works, but if i've set the DIV to display:inline or display:inline-block then it should work just like a SPAN.. This should be incredibly simple! ARGH!

CSS

p {
    position:relative;
}

.trigger {
    display:inline-block;
    position:relative; 
}

.toolTip {
    display:none;
    position:absolute;
    top:0;
    left:0;

}

.triangle {
    display:inline;
    position:absolute;
    top:0;
    left:0;
}

HTML

<p>
    Hello this is an example paragraph and I love to talk about typography
    here on somewhere in between the this and now when I see all of the
    dogs running around the streets I'm like oh my goodness puppy what are
    you doing to the cats when  

    <div class="trigger">TRIGGER TRIGGER
        <div class="toolTip">
            This part is hidden right now, this will be the tooltip, for testing
            purposes it is hidden.
            <div class="triangle"></div>
        </div>
    </div>

    in that one movie and i'm
    like oh wow this is insane i dont know what to even think when I see
    all of the cats gone, okay i'm gonna stop now mr person there. I'm like 
    oh my goodness puppy what are
    you doing to the cats when you see them, now they're all vanished
    since you came to town puppy
</p>    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

べ繥欢鉨o。 2024-12-20 04:24:08

您不能将块级元素放入段落内。由于 div 是块级元素,因此浏览器的行为就好像您编写了以下内容:

<p>foo bar</p>
<div class="trigger">....

这与人们在谈论 CSS 时讨论内联与块略有不同。段落元素的结尾是在浏览器读取 HTML 时、应用 CSS 之前确定的。

另一方面,跨度是内联元素,因此可以工作。

You can't put block level elements inside paragraphs. Since divs are block level elements, the browser acts as if you had written this instead:

<p>foo bar</p>
<div class="trigger">....

This is slightly different from when people discuss inline vs block when talking about CSS. The end of the paragraph element is determined while the browser is reading the HTML, before CSS is applied.

On the other hand, spans are inline elements, so that works.

不气馁 2024-12-20 04:24:08

将 div 替换为内联元素即可:

<span class="trigger">TRIGGER TRIGGER
    <span class="toolTip">
        This part is hidden right now, this will be the tooltip, for testing
        purposes it is hidden.
        <span class="triangle"></span>
    </span>
</span>

Replacing your divs with inline elements will work :

<span class="trigger">TRIGGER TRIGGER
    <span class="toolTip">
        This part is hidden right now, this will be the tooltip, for testing
        purposes it is hidden.
        <span class="triangle"></span>
    </span>
</span>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文