Primer CSS 排版文字對齊


排版是任何開發人員網頁設計的關鍵方面。它包括選擇字體系列、合適的間距、大小和網頁中文字的對齊方式。正確的排版可確保網站的可讀性增強。

文字對齊是排版的一個重要組成部分,確保完美的對齊可能是一個挑戰,尤其對於初學者而言。這裡,我們為開發人員提供了 Primer CSS。在本文中,我們將討論 Primer CSS 中提供的文字對齊功能,並瞭解它如何幫助建立使用者友好的網站。因此,讓我們開始吧。

Primer CSS

Primer CSS 是 GitHub 設計系統建立的 CSS 開源框架。它專為 Web 開發人員設計,使他們能夠快速建立響應式和自定義的網站。它提供了一套多功能的內建元件,例如排版、按鈕、警報、截斷、選單、導航等。它易於使用,節省大量時間。

此外,它還為初學者提供了詳細的文件,以便隨時開始。此框架幾乎在所有現代瀏覽器中都受支援。但是,某些舊版本可能在其某些功能方面存在問題。

為了將 Primer CSS 整合到您的 HTML 檔案中,請使用以下 CDN 連結:

<link rel="stylesheet" href="https://unpkg.com/@primer/css@^20.2.4/dist/primer.css" />

排版文字對齊

文字對齊是 Primer CSS 提供的排版元件中的一個功能。它使開發人員能夠使用類來對齊網頁上的文字。

用於文字對齊的類如下:

  • text-left

  • text-center

  • text-right

“text-left” 類

此類使我們能夠將文字對齊到頁面左側。以下是此類的語法:

<div class= "text-left"> </div>

示例

<html>
<head>
   <link rel="stylesheet" href="https://unpkg.com/@primer/css@^20.2.4/dist/primer.css" />
   <style>
      * {
         margin: 10px;
         padding: 2px;
      }

      h1 {
         color: brown;
         text-decoration: underline;
         font-family: Georgia;
      }
   </style>
</head>
<body>
   <h1> Primer CSS Typography text alignment </h1>
   <div>
      <p> This div element contains text which is aligned by default. </p>
      <p class="text-left"> This div element contains text which is aligned towards the left using the text-left class of Primer CSS. </p>
   </div>
</body>
</html>

如上所示,預設情況下文字會對齊到頁面的左側。

“text-center” 類

此類使我們能夠將文字對齊到頁面或螢幕的中心。以下是此類的語法:

<div class= "text-center"> </div>

示例

<html>
<head>
   <link rel="stylesheet" href="https://unpkg.com/@primer/css@^20.2.4/dist/primer.css" />
   <style>
      * {
         margin: 10px;
         padding: 2px;
      }
      h1 {
         color: brown;
         text-decoration: underline;
         font-family: Georgia;
      }
   </style>
</head>
<body>
   <h1> Primer CSS Typography text alignment </h1>
   <div>
      <p> This div element contains text which is aligned by default. </p>
      <p class="text-center"> This div element contains text which is aligned towards the center using the text-center class of Primer CSS. </p>
   </div>
</body>
</html>

響應式文字對齊

響應式文字對齊意味著文字對齊將根據使用者不同螢幕尺寸或裝置相應地調整其值。換句話說,文字的對齊方式將隨著螢幕型別的變化而變化,例如手機、平板電腦、桌上型電腦、PC 等。

使您的文字具有響應性對於您的網站非常重要,以便使其使用者友好且具有吸引力。Primer CSS 提供此功能,可以透過使用類在排版元件中進行響應式文字對齊。

語法

<div class= "text-left text-sm-center text-lg-right"> </div>

示例

<html>
<head>
   <link rel="stylesheet" href="https://unpkg.com/@primer/css@^20.2.4/dist/primer.css" />
   <style>
      *{
         margin: 0;
         padding: 0;
      }
      h1{
         color: orange;
         text-decoration: underline;
         font-family: Calibri;
      }
      div{
         font-size: 16px;
      }
   </style>         
</head>
<body>
   <h1> Primer CSS Typography text alignment </h1>
   <div class= "text-sm-left text-md-center text-lg-right">
      This text will be left aligned in small screen devices (screen size: up to 760 pixels), centrally aligned for medium screen devices (screen size: 768- 1012 px) and right aligned in large devices (screen size: above 1012 pixels)
   </div>
</body>
</html>

使用 Primer CSS 進行文字對齊的優勢

使用 Primer CSS 提供的用於文字對齊的排版類使您的網站保持一致且吸引人。由於存在預定義的類,因此您可以輕鬆地應用它們,而無需編寫冗長的 CSS 程式碼。它還使開發人員能夠使網站具有響應性和使用者友好性。由於此響應式功能,對齊方式將在所有現代瀏覽器和裝置中相容。

結論

在本文中,我們詳細討論了 Primer CSS。我們還學習了用於文字對齊的不同排版類及其示例。進行響應式文字對齊是建立吸引人網站的重要組成部分。

更新於: 2023年4月28日

132 次檢視

開啟您的 職業生涯

透過完成課程獲得認證

開始學習
廣告

© . All rights reserved.