html - 溢出换行未应用于文本

标签 html css angular

问题

我目前有一个使用 Angular 构建的侧边菜单,它在我的屏幕(4k 分辨率)上运行良好。问题是在较小的屏幕上,菜单中的文本不会换行,因此它会溢出容器 div。我已尝试将 overflow-wrap: break-word; 应用于文本,但这不起作用。

如有任何帮助,我们将不胜感激。

您可以看到以下问题:

Text overflowing div


代码

组件的 HTML:

<div class="sidebar animated fadeIn">
  <div class="header">
    <div style="display:block;margin-left:auto;margin-right:auto;width:100%;">
      <img src="../../../assets/images/logo.svg" style="width:100%" />
    </div>
  </div>
  <div class="spacer"></div>
  <div class="menu-item" *ngFor="let item of items" (click)="goTo(item.path)">
    <i class="material-icons">{{item.icon}}</i>
    <h3 class="text">{{item.name}}</h3>
  </div>
</div>

组件的样式:

.sidebar {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 2;
  width: 10%;
  background: rgba(191, 158, 69, 1);
  background: -moz-linear-gradient(top, rgba(191, 158, 69, 1) 0%, rgba(250, 239, 210, 1) 100%);
  background: -webkit-gradient(
    left top,
    left bottom,
    color-stop(0%, rgba(191, 158, 69, 1)),
    color-stop(100%, rgba(250, 239, 210, 1))
  );
  background: -webkit-linear-gradient(bottom, rgba(191, 158, 69, 1) 0%, rgba(250, 239, 210, 1) 100%);
  background: -o-linear-gradient(bottom, rgba(191, 158, 69, 1) 0%, rgba(250, 239, 210, 1) 100%);
  background: -ms-linear-gradient(bottom, rgba(191, 158, 69, 1) 0%, rgba(250, 239, 210, 1) 100%);
  background: linear-gradient(to top, rgba(191, 158, 69, 1) 0%, rgba(250, 239, 210, 1) 100%);
  filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#bf9e45', endColorstr='#faefd2', GradientType=0 );
  box-shadow: 5px 0 15px rgba(0, 0, 0, 0.5);
}

.header {
  width: 100%;
}

.spacer {
  margin-top: 3em;
}

.menu-item {
  border-top: 1px solid darkgray;
  padding-left: 2em;
  height: 3em;
  display: flex;
  align-items: center;
  cursor: pointer;
}

.menu-item .text {
  margin-left: auto;
  margin-right: auto;
  overflow-wrap: break-word;
}

最佳答案

添加此属性 word-break: break-all;

.menu-item .text {
  margin-left: auto;
  margin-right: auto;
  /*overflow-wrap: break-word;*/
  word-break: break-all;
}

关于html - 溢出换行未应用于文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54998583/

相关文章:

css - 样式 ng2-bootstrap 的 typeahead list-items

angular - Mat-form-field - 失焦时的样式和 mat-input 中的文本

angular - PhotoEditorSDK 在手动导出时阻止下载

html - 去除不必要的空格 - "unnecessary"是关键

javascript - 使用来自 PHP 的查询填充 HTML 元素

html - 无法将表单提交到 freecodecamp 模拟 url

jquery - 多个 Jquery 脚本

javascript - CSS 颜色属性不起作用

javascript - 调整窗口大小时扩展的字体大小

javascript - 为 TH 伪元素添加点击事件,从 TH 获取数据属性并防止 TH 事件在点击时触发