任何人都可以帮忙吗?我不希望文本溢出到左侧。我需要<p>
自动添加换行符。
这是CSS:
article {
padding: 5px;
margin: 1px 0px;
border: 2px solid #4afbd9;
float: left;
}
HTML:
<article id="the_article">
<h1>Hello guys </h1>
<p>wefeasdfasdfasdfaewgewtawerrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrfgrrrrrrrrrrrrrrrrdgdsffgsdfgsdfgsdfgsdfggsdfgsdfgsdfsdfgsdfgsdfggsdfgsdfgsdfrrrrrrdg</p>
</article>
答案 0 :(得分:5)
您需要将word-wrap: break-word
设置为父元素(示例中为<article>
)
article {
word-wrap: break-word;
}
p {
background-color: yellow;
width: 50%;
height: 90px;
}
<article>
<p>wefeasdfasdfasdfaewgewtawerrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrfgrrrrrrrrrrrrrrrrdgdsffgsdfgsdfgsdfgsdfggsdfgsdfgsdfsdfgsdfgsdfggsdfgsdfgsdfrrrrrrdg</p>
</article>
有关word-wrap
的一些文档:
答案 1 :(得分:2)
只需在css。
中添加一个自动换行css属性word-wrap: break-word;
答案 2 :(得分:2)
您可以使用word-wrap:break-word
或word-break:break-all
article {
padding: 5px;
margin: 10px;
border: 2px solid #4afbd9;
float: left;
width:100px;
}
article:first-of-type {
word-wrap: break-word
}
article:last-of-type {
word-break: break-all
}
<article>
<p>wefeasdfasdfasdfaewgewtawerrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrfgrrrrrrrrrrrrrrrrdgdsffgsdfgsdfgsdfgsdfggsdfgsdfgsdfsdfgsdfgsdfggsdfgsdfgsdfrrrrrrdg</p>
</article>
<article>
<p>wefeasdfasdfasdfaewgewtawerrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrfgrrrrrrrrrrrrrrrrdgdsffgsdfgsdfgsdfgsdfggsdfgsdfgsdfsdfgsdfgsdfggsdfgsdfgsdfrrrrrrdg</p>
</article>