可以使用CSS的word-wrapword-break属性来实现在指定字符数换行的效果。将.content的样式修改如下:

.content {
  word-wrap: break-word;
  word-break: break-all;
  white-space: pre-wrap;
  max-width: 300px; /* 设置最大宽度为300px */
}

这样,当内容超过15个字符时会自动换行,并且不会超出最大宽度300px的范围。

!DOCTYPE htmlhtmlhead title微信聊天界面title stylechat-container width 100; height 100vh; margin 0 auto; border 1px solid #ccc; border-radius 5px; padding 20px;chat height 300px; overflow-y scro

原文地址: https://www.cveoy.top/t/topic/inQr 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录