将空格转换为换行符 [英] converting white space into line break

查看:431
本文介绍了将空格转换为换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用CSS在每个空白处添加换行符?

Is it possible to add a line break on each white space using CSS?

例如,如果我有字符串"Format It",我希望将其显示为

For example, if I have string "Format It" I would like to display it like

Format
It

使用CSS.

推荐答案

您可以使用word-spacing属性.它定义了单词之间的间隔.如果将其设置为容器的大小,则会强制换行...

You can use the word-spacing property. It defines the space between the words. If you set it to the size of the container, it will force a line break...

由于它不接受百分比值,因此可以使用vw之类的相对值.

Since it doesn't accept percentual values, you can use relative values like vw.

div {
    word-spacing: 100vw;
}

http://jsfiddle.net/ApL3h/

这篇关于将空格转换为换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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