防止所选文字行之间出现空格 [英] Prevent white space between selected text lines

查看:36
本文介绍了防止所选文字行之间出现空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户在单个元素中选择多行文本时,选择背景没有空格,但是如果将每行放在单独的元素中,则会出现白线吗?

How come when a user selects multiple lines of text inside a single element, the selection background has no gaps in it, but if I put each line in a separate element, white lines appear?

请考虑以下代码段:

.line {
  font-family: 'Courier';
  font-size: 14px;
  line-height: 17px;
  white-space: pre;
}

<div class="line">Text 1
Text 2</div>
<div class="line">Text 3</div>
<div class="line">Text 4</div>

如果选中了所有文本,则前两行会合并"在一起,但是即使所有四行中实际文本之间的距离相同,白线也会出现在第三行和第四行之前?

If all the text is selected, first two lines are "merged" together, but white lines appear before third and fourth lines, even though the distance between actual text in all four lines is identical?

如何在不更改字体或间距的情况下摆脱它们?

How do I get rid of them without changing font or spacing?

推荐答案

您可以尝试使用 line-height:1; line-height:1.1; 您的文字失去可读性.我通常将 line-height:1.6; 设置为14px左右的字体大小.

You could try with a line-height: 1; or line-height: 1.1; but your text loses in readibility. I usually set a line-height: 1.6; for font sizes around 14px.

.line {
  font-family: 'Courier';
  font-size: 14px;
  line-height: 1;
  white-space: pre;
}

<div class="line">Text 1
Text 2</div>
<div class="line">Text 3</div>
<div class="line">Text 4</div>

这篇关于防止所选文字行之间出现空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆