Avoid breaking line between two words when resizing [duplicate]

眉间皱痕 提交于 2019-12-04 02:55:06
T.J. Crowder

You use a nonbreaking space. The HTML entity for it is  . You'll probably want a non-breaking hyphen (‑) in T-2 as well:

Ask for it it when contracting until 2016/09/30 with T‑2 Rate

Example:

var target = document.getElementById("target");
var originalWidth = target.innerWidth || target.clientWidth;
var width = originalWidth;
tick();
function tick() {
  width = width < 10 ? originalWidth : (width - 10);
  target.style.width = width + "px";
  setTimeout(tick, 400);
}
#target {
  display: inline-block;
  border: 1px solid #ddd;
}
<div id="target">Ask for it it when contracting until 2016/09/30 with T&#8209;2&nbsp;Rate</div>

Just use <span style="white-space: nowrap"> for nonbreaking parts, as MDN states.

Ask for it it when contracting until 2016/09/30 with <span style="white-space: nowrap">T-2 Rate</span>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!