文本溢出:省略号无法在IE和Edge中预标记或用空格预文本所有行

时间:2019-03-15 06:59:22

标签: html css google-chrome internet-explorer

在IE中,text-overflow: ellipsis<pre>标签文本和white-space: pre文本无效。仅对于第一行,它可以正常工作,而对于其余各行,它不能在Chrome浏览器中工作,对于所有浏览器都可以正常工作。

enter image description here

.myText {
  white-space: pre;
  color: blue;
  -ms-text-overflow: ellipsis;
  text-overflow: ellipsis;
  overflow: hidden;
}
<!DOCTYPE html>
<html lang="en">
<head>
  <title>Angular Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
</head>


<body>

<div >

<div class="container">
  <h1>Pre Tag or Pre Text with Textoverlow ellipsis:</h1>
<div style="WIDTH: 100PX;">
<div class="myText">print "Hello world, how are you doing today? 
Is this getting cut off yet?
Hello world, how are you doing today? </div>
</div>
</div>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

在每个新行中添加span

JSFiddle

.myText span {
  white-space: pre;
  text-overflow: ellipsis;
  overflow: hidden;
  color: blue;
  display: block;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>


<div class="container">
  <h1>Pre Tag or Pre Text with Textoverlow ellipsis:</h1>
  <div style="WIDTH: 100PX;">
    <div class="myText">
      <span>print "Hello world, how are you doing today?</span>
      <span>Is this getting cut off yet?</span>
      <span>Hello world, how are you doing today?</span>
    </div>
  </div>
</div>