代码之家  ›  专栏  ›  技术社区  ›  Tachyon

溢出换行未应用于文本

  •  0
  • Tachyon  · 技术社区  · 6 年前

    问题

    我现在有一个侧菜单,我已经建立了使用角度,它在我的屏幕上工作得很好(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;
    }
    
    1 回复  |  直到 6 年前
        1
  •  2
  •   Lalji Tadhani    6 年前

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

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