使用 CSS 設定文字顏色


要設定文字顏色,請在 CSS 中使用 color 屬性。您可以使用顏色名稱、十六進位制數值、RGB 值或 HSL 值設定顏色。

示例

 實際演示

<!DOCTYPE html>
<html>
<head>
<style>
span {
   background-color: orange;
   color: white;
}
p.demo {
   display: none;
}
span.demo1 {
   display: inline;
}
</style>
</head>
<body>
<h1>Match Details</h1>
<div>
Match will begin at <p class="demo">9AM</p> 10AM on 20th December.
</div>
<div>
Match will end at <span class="demo1">5PM</span> on 20th December.
</div>
</body>
</html>

輸出

示例

我們現在來看另一個示例 −

 實際演示

<!DOCTYPE html>
<html>
<head>
<style>
p.demo1 {
   word-spacing: 1cm;
   color: #F8E61C;
}
p.demo2 {
   word-spacing: 40px;
}
</style>
</head>
<body>
<h1>Demo Heading</h1>
<h2>Heading2</h2>
<p class="demo1">This is demo text.</p>
<h2>Heading2</h2>
<p class="demo2">This is demo text.</p>
</body>
</html>

輸出

更新於:2019-12-26

408 次檢視

開啟您的 職業生涯

完成課程以獲得認證

開始
廣告
© . All rights reserved.