CSS - line-break 属性



line-break 属性用于确定如何在一段文本中换行。这非常重要,因为它使页面更易读和易于理解。

可能的值

  • auto:应用默认换行规则。

  • loose:应用限制最少的换行规则。

  • normal:应用最常见的换行规则。

  • strict:应用最严格的换行规则。

  • anywhere:允许浏览器在任何位置、任何字符处应用换行规则。

  • initial:设置初始值。

  • inherit:继承父元素的值。

应用于

所有 HTML 元素。

DOM 语法

object.style.lineBreak = "strict";

示例

这是一个示例

<html>
<head>
<style>
   p {
      border: 2px solid blue;
      width: 200px;
   }
   .normal {
      line-break: normal;
   }
   .loose {
      line-break: loose;
   }
   .strict {
      line-break: strict;
   }
   .auto {
      line-break: auto;
   }
   .anywhere {
      line-break: anywhere;
   }
</style>
</head>
<body>
   <h2>Line Break</h2>
      <p class="normal">Normal - CSS provides property <b>line-break</b> that is useful in determining how to break lines in a block of text.</p>
      <p class="loose">Loose - CSS provides property <b>line-break</b> that is useful in determining how to break lines in a block of text</p>
      <p class="strict">Strict - CSS provides property <b>line-break</b> that is useful in determining how to break lines in a block of text</p>
      <p class="auto">Auto - CSS provides property <b>line-break</b> that is useful in determining how to break lines in a block of text</p>
      <p class="anywhere">Anywhere - CSS provides property <b>line-break</b> that is useful in determining how to break lines in a block of text</p>
</body>
</html> 
广告