如何使div垂直而不是水平溢出?

时间:2017-07-29 17:43:48

标签: html css

我有一个网页的一小部分,它将包含一个大文本,我希望它垂直展开而不是水平展开,我知道可以使用overflow:visible | hidden | scroll | auto | initial | inherit;水平和垂直都有overflow-x和overflow-y,但是这并没有解决我的问题,因为它们要么隐藏文本要么放一个滚动条,我希望那个div能够占据他想要的所有空间而只需要空间他横向移动,这是移动设备的半屏幕。

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
    <div width="50%" style="background-color:red">
        asdssssssssssssssssssssssssssssssssssdddddfsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
    </div>
</body>
</html>

文本将来自数据库,所以我不能用换行符或段落打破它,任何人都可以帮助我吗?

2 个答案:

答案 0 :(得分:2)

使用word-break: break-all;打破文字:

&#13;
&#13;
.container {
  word-break: break-all;
  overflow: auto;
  width: 50vw;
  height: 50vh;
  background-color:red;
}
&#13;
<div class="container">
 asdssssssssssssssssssssssssssssssssssdddddfsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssasdssssssssssssssssssssssssssssssssssdddddfsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssasdssssssssssssssssssssssssssssssssssdddddfsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssasdssssssssssssssssssssssssssssssssssdddddfsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssasdssssssssssssssssssssssssssssssssssdddddfsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssasdssssssssssssssssssssssssssssssssssdddddfsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssasdssssssssssssssssssssssssssssssssssdddddfsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssasdssssssssssssssssssssssssssssssssssdddddfsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssasdssssssssssssssssssssssssssssssssssdddddfsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssasdssssssssssssssssssssssssssssssssssdddddfsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssasdssssssssssssssssssssssssssssssssssdddddfsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssasdssssssssssssssssssssssssssssssssssdddddfsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssasdssssssssssssssssssssssssssssssssssdddddfsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssasdssssssssssssssssssssssssssssssssssdddddfsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssasdssssssssssssssssssssssssssssssssssdddddfsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssasdssssssssssssssssssssssssssssssssssdddddfsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssasdssssssssssssssssssssssssssssssssssdddddfsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssasdssssssssssssssssssssssssssssssssssdddddfsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssasdssssssssssssssssssssssssssssssssssdddddfsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

overflow-y:scroll;

这样做