0

基本上,我的 div 中有两个 a 标签,它们是可变的。但如果它们不止一个词,或者只是带有更多字母的词,我不希望它们在需要换行时分开。我有这个演示,我在其中写下了一些可能的结果。第一个 div 是我想阻止的现在发生的事情。http://jsfiddle.net/tVC43/1/

  <div class="box">
   welcome to <a>xxx</a> part.
  <a>hi thomas</a>
  </div>
  <div class="box" style="left:170px;">
   welcome to <a>xxx</a> part.
  <a style="display:block;">hi thomas</a>
  </div>
  <div class="box" style="left:340px;">
   welcome to <a>xxxxxxx</a> part.
  <a>hi thomas</a>
  </div>
4

2 回答 2

2

使用不间断空格而不是普通空格,例如<a>hi&nbsp;thomas</a>,或在元素上使用 CSS 设置white-space: nowrap,或将内容包裹在<nobr>...</nobr>.

于 2013-01-29T09:02:58.387 回答
0

添加display:block

a:last-child, span:last-child{display:block}

演示

于 2013-01-29T09:22:05.060 回答