内联元素导致文本停止换行?这么简单?
http://jsfiddle.net/nicktheandroid/SsfpG/
我不明白为什么这些内联元素是导致段落停止换行,或者未完成在内联元素之前放置文本,换句话说:某些内容导致 DIV 设置为 display:inline-block
之前的换行符,甚至如果我只需将其设置为 display:inline
即可。如果我将 DIV 更改为 SPAN,那么它就可以工作,但是如果我将 DIV 设置为 display:inline
或 display: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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不能将块级元素放入段落内。由于 div 是块级元素,因此浏览器的行为就好像您编写了以下内容:
这与人们在谈论 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:
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.
将 div 替换为内联元素即可:
Replacing your divs with inline elements will work :