简体   繁体   English

如何在对齐的CSS中删除空格

[英]how to remove white space in justified css

If I am using 如果我正在使用
text-align:justify
paragraph shows unwanted space between words to maintain specified width. 段落显示单词之间不需要的空格以保持指定的宽度 Searched in internet but didn't get any proper result. 在互联网上搜索但没有得到任何正确的结果。 I used white-space also but no use 我也使用了白色空间,但没有用

fiddle : fiddle 小提琴: 小提琴

The closest solution would be using word-break: break-all but this will also break words. 最接近的解决方案是使用分word-break: break-all但这也会破坏单词。 If you are ok with this then go with this solution: 如果您对此感到满意,请使用此解决方案:

.sample_test p{
    word-break: break-all;
}

Fiddle 小提琴

When you are using text-align: justify , you are asking browsers to add spacing, and browsers implement this as added spacing between words. 当您使用text-align: justify ,您要求浏览器添加间距,并且浏览器将其实现为单词之间的间距。 According to CSS Text Module Level 3 LC, you could additionally use text-justify: distribute to ask browsers to use added spacing both between words and between characters in words, to achieve a more balanced result, but it is debatable whether the results are really better, and this feature has been implemented only in IE (long ago). 根据CSS Text Module Level 3 LC,您还可以使用text-justify: distribute来要求浏览器在单词之间和单词之间使用添加的间距来实现更平衡的结果,但结果是否真的存在争议更好,此功能仅在IE(很久以前)中实现。

What you can do to improve the situation is to use hyphenation. 你可以做些什么来改善这种情况就是使用连字法。 This generally reduces the need for added spacing, though of course it cannot remove it. 这通常减少了增加间距的需要,但当然它不能将其移除。 The most effective way is to use Hyphenator.js , which means that you need to declare the language of your page, eg <html lang=en> , to set the hyphenate class on any elements where text should be hyphenated, eg with <body class=hyphenate> to hyphenate everything, and to just add the code 最有效的方法是使用Hyphenator.js ,这意味着您需要声明页面的语言,例如<html lang=en> ,在文本应该连字符的任何元素上设置hyphenate类,例如<body class=hyphenate>连接所有内容,并只添加代码

<script src=http://hyphenator.googlecode.com/svn/tags/Version%204.2.0/Hyphenator.js></script>
<script>Hyphenator.run();</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM