[英]Word wrap in split text
I want to animate text in paragraph in my site by letters. 我希望用字母为我网站上的段落中的文字添加动画效果。 I split my text and wrap each letter in <span>
, so I built structure like this with jQuery: 我拆分文本并将每个字母包装在<span>
,所以我用jQuery构建了这样的结构:
<p>
<span>H</span>
<span>E</span>
<span>L</span>
<span>L</span>
<span>O</span>
</p>
For using css transforms I added property inline-block
for spans. 为了使用css转换,我为spans添加了属性inline-block
。 Now animation works fine but I have problem with word wrapping. 现在动画工作正常,但我有自动换行的问题。 Text wrap after each letter not only on space. 每个字母后面的文本换行不仅在空格上。
I tried to use word-wrap
and white-space
but it doesn't work :/ What can I do ? 我尝试使用word-wrap
和white-space
但不起作用:/我该怎么办?
It works good with float:left;
它适用于float:left;
instead of display: inline-block;
而不是display: inline-block;
p{
font-size: 60px;
overflow: hidden;
}
span{
float: left;
}
Just saw that on an answer on SO : 刚看到SO上的答案:
inline-blocks are like characters, which means spaces are counted in the width too. 内联块就像字符一样,这意味着空间也在宽度上计算。 Remove spaces/new lines between divs to get what you what. 删除div之间的空格/换行以获得你的想法。 Or switch to other layout method, like float: left. 或者切换到其他布局方法,如float:left。
CSS margins: Why does this layout behave this way? CSS边距:为什么这种布局会这样?
您可以使用“letter-spacing”css来标记p以增加或减少空间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.