如何让html元素始终包含内容?

时间:2018-01-29 09:05:53

标签: html css frontend

enter image description here

您会看到,当浏览器宽度足够窄时,会出现滚动条。当我向右拖动滚动条时,内容超出了html元素。 这是代码:

body {
  border: 1px solid;
}
lkjlaksjfklajfkalsdddddddaaaadfajflkajflkajflkajflkjasklfjaslkfjaklsjfklasjfklasjfaklsfsd

1 个答案:

答案 0 :(得分:2)

您可以使用word-break: break-all;规则确保长字不会溢出容器:



body {
  border: 1px solid;
  word-break: break-all;
}

lkjlaksjfklajfkalsdddddddaaaadfajflkajflkajflkajflkjasklfjaslkfjakjfklasjfklasjfaklsfsdasdfasdfadsfasdfasdfadfasdfadsfasd