简体   繁体   English

段落自动换行

[英]Paragraph auto newline

In DIV I put paragraph but when text is longer then div,it does not make new line but out of the DIV.I try with: -moz-hyphens:auto; -ms-hyphens:auto; -webkit-hyphens:auto; hyphens:auto; word-wrap:break-word; 在DIV中我放了段落,但是当文本比div更长时,它不会创建新行但是在DIV之外。我尝试使用: -moz-hyphens:auto; -ms-hyphens:auto; -webkit-hyphens:auto; hyphens:auto; word-wrap:break-word; -moz-hyphens:auto; -ms-hyphens:auto; -webkit-hyphens:auto; hyphens:auto; word-wrap:break-word; but it doesn't work.Any suggestions? 但它不起作用。任何建议?

Here is code of div: 这是div的代码:

<div id="content">
<p id="test">tfufygigighfetefddddddddddddsssssssssssssssssssssssssssssssssssssssssssfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff</p>
</div>

css code of div: div的css代码:

#content {
float:left;
position:absolute;
background-color:#D4D3D0;
height:500px;
width:80%;
}

and the css of paragraph: 和段落的CSS:

p.test {
-moz-hyphens:auto;
-ms-hyphens:auto;
-webkit-hyphens:auto;
hyphens:auto;
word-wrap:break-word;
}

I'm going out on a limb here! 我要出去了! But I believe you need to put word-wrap: break-word; 但我相信你需要把word-wrap: break-word; in the div css, instead of the <p> css. 在div css中,而不是<p> css。 It works for me! 这个对我有用!

Edit: 编辑:

Oh wait, I can see what you did wrong. 哦等等,我能看出你做错了什么。 The name of the <p> tag isn't p.test it's #test ! <p>标签的名称不是p.test它是#test

add word-wrap: break-word; 添加word-wrap: break-word; to #content #content

You can also remove those styles from your p element. 您还可以从p元素中删除这些样式。

I believe you need to add this two line in #content 我相信你需要在#content中添加这两行

#content{
    word-wrap: break-word;
    white-space:pre-wrap;
}

This will print each sentence in each line, without <br> 这将打印每行中的每个句子,没有<br>

<p style="font-family:courier;white-space: pre;">
First Line
Second Line
Third Line
</p>

For example check jsfiddle http://jsfiddle.net/muthupandiant/sgp8rjfs/ 例如,检查jsfiddle http://jsfiddle.net/muthupandiant/sgp8rjfs/

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

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