如何在HTML5中定義可能的換行符?


在本文中,我們將討論如何在HTML5中定義可能的換行符。換行符用於在文字或內容塊中建立新行。它通常用於在資訊片段之間建立分隔,或控制網頁上內容的佈局。

方法

我們有兩種不同的方法來使用HTML5定義可能的換行符,包括以下這些:

  • 使用“<br> 元素”

  • 使用“<wbr> 元素”

讓我們詳細檢視每個步驟。

方法1:使用“<br> 方法”

第一種方法是使用HTML5定義可能的換行符為“<br>”。當您想要將文字分成多行而無需開始一個新段落或在它們之間新增額外的空格時,換行標籤很有用。只需在您想要建立換行符的位置新增“<br>”標籤,瀏覽器就會在下一行顯示內容。

示例

以下是如何使用“<br>”在HTML5中定義可能的換行符的示例。

<!DOCTYPE html>
<html>
<head>
   <title>Using the <br> Tag</title>
   <style>
      h1 {
         color: blue;
         text-align: center;
      }
      h2 { 
         color: green;
      }
      p {
         font-size: 18px;
         line-height: 1.5;
      }
   </style>
</head>
<body>
   <h1>Ttorials Point Articles</h1>
   <h2>
      How to defines a possible line-break
   </h2>
   <h3>Define HTML, CSS, JS?</h3>
   <p>
      HTML stands for Hyper-Text Markup Language and is how content is structured in code for a browser to display. Virtually, every page you view in a browser today has it’s content structured in HTML.<br> CSS stands for cascading style sheets and this is how content in HTML is styled and designed. Want to make some text BOLD, change the color of some text, or give something a background? CSS is the main way that is achieved today.<br> Javascript is a programming language for the web. All this means is that when you want something to move, change, or react on a website javascript is normally the thing doing it. Javascript handles logic so the if then’s of web design and development.
   </p>
</body>
</html>

方法2:使用“<wbr> 方法”

第一種方法是使用HTML5定義可能的換行符為“<wbr>”。當您想指示一個單詞可以跨行斷開的位置時,可以使用“<wbr>”標籤。這對於可能不適合單行顯示的長單詞或URL很有用。

示例

以下是如何使用“<wbr>”在HTML5中定義可能的換行符的示例。

<!DOCTYPE html>
<html>
<head>
   <title>Using the <wbr> Tag</title>
   <style>
      h1 {
         color: blue;
         text-align: center;
      }
      h2 {
         color: green;
      }
      p {
         font-size: 18px;
         line-height: 1.5;
      }
      span {
         background-color: yellow;
      }
   </style>
</head>
<body>
   <h1>Ttorials Point Articles</h1>
   <h2>
      Using the <wbr> Tag
   </h2>
   <p>
      The <wbr> tag is used to suggest a line break opportunity in a long word or URL that cannot be broken up and must stay on one line.<br> Here's an example: <span>https://tutorialspoint.tw/index.htm</span><wbr>.com
   </p>
</body>
</html> 

結論

在本文中,我們檢查了兩種不同的方法來使用HTML5定義可能的換行符。“<br>”和“<wbr>”這兩種方法。“<br>”標籤用於在段落或其他文字塊中插入換行符,而“<wbr>”標籤用於指示單詞可以跨行斷開的位置。

更新於:2023年3月27日

605 次瀏覽

啟動您的職業生涯

完成課程獲得認證

開始學習
廣告
© . All rights reserved.