【问题标题】:Text overflows beyond div occasionally in Chrome 43在 Chrome 43 中,文本偶尔会超出 div
【发布时间】:2015-05-29 16:09:11
【问题描述】:

我有一个基本块(紫色),里面有一些可变长度的文本。 div 是相对位置的,也是响应式的,因此它的宽度等以 % 为单位。

我们的一些用户在 Chrome 最新版 (v43.0.2357.65) 和 WinXP 上看到文本溢出到紫色框的边缘。这是一时兴起的,因此很难重现。我正在尝试修复 CSS,以便文本不会溢出。我在包含文本的 div 上也有一个 max-width 和 break-word 属性。

该网站是荷兰语。

<div class="mt-landing__section-notification">
<div class="mt-landing__section-notification__info-icon icon-info"></div>
                <div class="mt-landing__section-notification__close-icon"></div>
                <div class="mt-landing__section-notification__content">
                    <div class="mt-landing__section-notification__message">
                        This is where the text is. 
                    </div>
                </div>
            </div>

这是最外层 div 上的 CSS 和包含文本的那个:

.mt-landing__section-notification {
    z-index: 1;
    width: 64.5%;
    background-color: #411E4E;
    padding: 20px;
    color: #fff;
    box-sizing: border-box;
    position: relative;
    float: left;
    margin-top: 0px;
    display: block;
}
 .mt-landing__section-notification__message {
     line-height: 24px;
     margin-top: -3px;
     word-wrap: break-word;
     max-width: 100%;
}
 .mt-landing__section-notification__content {
     margin: 0px 50px; 
  }
  .mt-landing__section-notification__info-icon {
       width: 50px;
       float: left;
       font-size: 24px;
  }
  .info-icon {
      font-family: mt-icons;
      font-style: normal;
      font-weight: 400;
      font-variant: normal;
      text-transform: none;
      line-height: 1;
   }
   .info-icon::before {
        content: '\e617';
    }

任何想法为什么文本溢出?

【问题讨论】:

  • 你能把你正在使用的整个字符串粘贴到 div 中吗?
  • 这里是“Heeft u vanaf 23 mei een abonnementenwijziging doorgegeven?Door een systeemstoring kan he zijn dat deze wijziging nog niet is verwerkt. Wij hopen dit zo spoedig mogelijk te herstellen。借口。”但是我必须提到这个字符串是动态的,它是通过一种管理界面设置的,最终作为 html 模板上的服务器端变量。对于不同的文本,我也遇到过这个问题。
  • 左边的图标是哪里来的?
  • 您的 CSS 是正确的,正如 @BenPhilipp 所说,可能问题是由于左侧图标将所有内容“推”到右侧。
  • 我的图标只是一个图标字体,我将字体系列定义为自定义字体和伪元素中的内容值。图标信息 { 字体样式:正常;字体粗细:400;字体变体:正常;文本转换:无;行高:1; } .icon-info:before { 内容:"\e617"; }

标签: html css cross-browser


【解决方案1】:

看起来你的信息图标可能是这里的罪魁祸首。

要么 a) 将图标设置为position:absolute,将容器设置为position:relative,这会将图标从流中取出,因此不会将文本推到右侧,

或 b) 也许使用图标作为背景图像。只需增加容器的padding-left 并将其添加为背景图像。我发现这是保持秩序井然的最简单方法,同时仍然灵活且响应迅速:

https://jsfiddle.net/svArtist/s3xc3nro/

.mt-landing__section-notification {
    z-index: 1;
    width: 64.5%;
    padding: 20px;
    color: #fff;
    box-sizing: border-box;
    position: relative;
    float: left;
    margin-top: 0px;
    display: block;
}
.mt-landing__section-notification__message {
    line-height: 24px;
    margin-top: -3px;
    word-wrap: break-word;
    max-width: 100%;
}

.icon-info{
background: url(http://www.grafik-wunder.de/klafo/images/info.png)  #411E4E no-repeat 10px center;
    padding-left: 50px;
    min-height: 50px;
    box-sizing:border-box;
}
<div class="mt-landing__section-notification  icon-info">
    <div class="mt-landing__section-notification__close-icon"></div>
    <div class="mt-landing__section-notification__content">
        <div class="mt-landing__section-notification__message">This is where the text is.</div>
    </div>
</div>

【讨论】:

  • 对不起,我忘了补充图标信息类也有以下css。 mt-landing__section-notification__info-icon { 宽度:50px;向左飘浮;字体大小:24px; } 你不认为这不应该干扰右边的文字。 .mt-landing_section-notification__content { margin: 0px 50px; }
  • 添加了原问题中cmets中谈到的所有css,以使其更加清晰。谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-31
  • 1970-01-01
  • 1970-01-01
  • 2013-02-22
  • 1970-01-01
相关资源
最近更新 更多