简体   繁体   English

如何阻止 IE 和 Edge 上的文本溢出 div

[英]How to stop text overflowing div on IE and Edge

Using flexbox on a video overlay div that shows/hides with Javascript and matches the auto size of the video.在视频覆盖 div 上使用 flexbox 显示/隐藏 Javascript 并匹配视频的自动大小。 The text on this overlay div wraps perfectly on every browser except IE and Edge where it overflows outside the div instead of wrapping.此覆盖 div 上的文本在每个浏览器上完美换行,除了 IE 和 Edge,它在 div 之外溢出而不是换行。

I've tried using white-space , overflow min-width and various CSS changes that have been suggested to others that have similar problems but none have worked for me.我尝试过使用white-spaceoverflow min-width和各种 CSS 更改,这些更改已向其他有类似问题但没有一个对我有用。

The code below is heavily cut back from its original form so hopefully I haven't left out anything important.下面的代码从其原始形式大幅削减,所以希望我没有遗漏任何重要的东西。 I have removed code for several other divs from within the main "Box" div that also hide/show with JS but are not showing while this div in question is showing so it is specific to this div as the other do not have long text fields.我已经从主“框”div 中删除了其他几个 div 的代码,这些 div 也使用 JS 隐藏/显示,但在显示该 div 时未显示,因此它特定于该 div,因为另一个没有长文本字段.

I have tried adding additional CSS to the H3 "infoText" to try to wrap, align, justify etc but nothing fixes this overflow problem on Edge and IE.我尝试在 H3“infoText”中添加额外的 CSS 以尝试换行、对齐、对齐等,但没有解决 Edge 和 IE 上的溢出问题。

<div id="Box">
  <video id="myvid" width="100%">
    <source src="video1.mp4">
  </video>

  <div id="intro"> // this div is an overlay for video player
      <h3 id="infoText">Lots of text goes here........</h3>
     // this text overflows on both sides of the div
      <button class="mybutton" id="start">Start</button>
  </div>
</div>


#Box {
  position: relative;
  width: 100%;
  height: auto;
}
#intro {
  width: 100%;
  height: 100%;
  position: absolute;
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  top: 0px;
}

After trying dozens of configurations within parent and child div CSS values I have solved this problem by adding max-width to the H3 element ID infoText .在父子 div CSS 值中尝试了数十种配置后,我通过将max-width添加到 H3 元素 ID infoText解决了这个问题。 Everything else on the style sheet has remained unchanged.样式表上的其他所有内容都保持不变。 This currently appears to solve the lack of wrapping problem on IE and Edge without causing any other apparent issues at this point.目前,这似乎解决了 IE 和 Edge 上缺少换行的问题,而此时不会导致任何其他明显的问题。 I'm assuming all other browsers have a default max-width so this problem doesn't occur inside flexbox so its difficult to understand why MS products don't.我假设所有其他浏览器都有一个默认的最大宽度,所以这个问题不会在 flexbox 内部发生,所以很难理解为什么 MS 产品没有。

#infoText {
max-width:80%;
}

If I understand correctly your article, you need to do something like this in your css style.如果我对您的文章的理解正确,您需要在您的 css 样式中执行类似的操作。

text-overflow: ellipsis;  /* IE 6+, FF 7+, Op 11+, Saf 1.3+, Chr 1+*/
-o-text-overflow: ellipsis;  /* for Opera 9 & 10 *
-ms-text-overflow: ellipsis; /*IE 8*/

I hope this helps you.我希望这可以帮助你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM