簡體   English   中英

新行分隔div內的單詞

[英]newline separating word inside div

基本上,我的div中有兩個標簽,它們是可變的。 但如果它們不止一個單詞,或者只是單詞中包含更多字母,我不希望它們在需要換行時分開。 我有這個演示,我寫下了一些可能的結果。 第一個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>

使用不間斷的空格而不是普通的空格,例如<a>hi&nbsp;thomas</a> ,或者在元素上使用CSS設置white-space: nowrap ,或者在<nobr>...</nobr>包裝內容<nobr>...</nobr>

添加display:block

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

DEMO

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM