目錄
如何在 HTML 中設定背景顏色?
首頁 web前端 html教學 HTML 顏色 

HTML 顏色 

Sep 04, 2024 pm 04:33 PM
html html5 HTML Tutorial HTML Properties HTML tags

本文介紹如何使用 HTML 以簡單易行的方式在網站中使用顏色。顏色在創建網站的外觀和感覺方面發揮著重要作用。 HTML 中沒有單獨的標籤;相反,它使用樣式屬性或顏色屬性。準確地說,顏色是使用層疊樣式表 (CSS) 嵌入到 HTML 元素中的。顏色賦予網頁優雅的外觀。為網頁新增顏色包括設定背景顏色、表格、段落等

如何在 HTML 中設定背景顏色?

讓背景顏色變亮使網站看起來更漂亮、更大膽。它是透過使用顏色、十六進制顏色代碼來完成的。 RGB 和 RGBA 顏色值(Alpha 值 0 到 1)。

使用 Html body 元素內的 Style 屬性將十六進位顏色直接套用於 Html 程式碼。十六進制是數字和字母的組合。以下是網頁背景顏色的範例。

代碼:

<!DOCTYPE html>
<title>My Sample</title>
<html>
<head>
<title>HTML BG Color</title>
</head>
<body style="background-color:red;">
<h1> This page is a demo </h1>
</body>
</html>
登入後複製

程式碼片段:

HTML 顏色 

要新增背景顏色,可以使用 bgcolor 屬性來顯示

body bgcolor=''>.它與除 HTML 5 之外的所有瀏覽器相容。

代碼:

<h3 style="color: blue">Color Name</h3>
<h3 style="color: #0000ff">Hexadecimal</h3>
<h3 style="color: rgb (0,0,255)">RGB Value</h3>
登入後複製

如何為 HTML 中的文字套用顏色?

對 HTML 文字套用顏色非常簡單;我們可以透過三種方式添加/更改文字的顏色,即十六進位顏色、HSL 值和顏色名稱。以下是將顏色應用到對應網頁的三種不同技術。

1.顏色名稱

當應用程式直接使用這些顏色名稱時,使用英文顏色名稱非常簡單。指定顏色名稱是直接方法,W3C已經公佈了16種基本顏色(黑色、黃色、紅色、栗色、灰色、石灰、綠色、橄欖色、銀色、水色、藍色、海軍藍、白色、紫色、紫紅色、青色)

2.福勝利

色相飽和度和亮度顏色值。色調定義為 0 到 360 度,飽和度和亮度定義為 0 到 100 %。

3.十六進位顏色

為了得到精確的結果,應用六位十六進位數。詳細來說,前兩位表示紅色,後兩位表示綠色,另外兩位表示藍色值,前面有「#」。

以下範例解釋了向文件應用顏色的不同方法。

代碼:

<head>
<title>EDUCBA</title>
<style type="text/css">
h1{
color:#97cae0;
background-color: hsl(200, 50%, 20%);
color: hsl(200, 20%, 90%);
}
h4{
color:rgb(0, 255, 0);
background-color: hsl(130, 10%, 30%);
color: hsl(280, 20%, 80%);
}
li{
color:rgba(12, 88, 120, 1);
background-color: hsl(210, 36%, 50%);
color: hsl(145, 45%, 81%);
}
</style>
</head>
<body>
<h1>EDUCBA</h1>
<h4>List of operating System</h4>
<ul>
<li> Windows</li>
<li>MACINTOSH</li>
<li>LINUX</li>
<li>UBUNTU</li>
</ul>
</body>
</html>
登入後複製

輸出:

HTML 顏色 

有不同的方法來設定文字顏色,因為 HTML 有很多可自訂的應用程式。
  • 套用樣式部分
  • 建立單獨的 CSS 樣式表
  • 換行文字

如何使用

The styles for Html documents

Each tag to be styled with colors.

輸出:

HTML 顏色 

5.建立個人 CSS 樣式

代碼:

.html 檔案:







  CSS style sheet

Multiple HTMl Document.

Hello world!

外部 CSS 檔案 lcolor.css:

代碼:

.lcolor { font-size: 40px;
color:red }

輸出:

HTML 顏色 <🎜>

How to Set Border Color in HTML?

It is done using an attribute border color=” “. It is done using the Html element

and even we can create 3D effects. The border color is applied using different attributes like border= “width”, bordercolor= “color def”, bordercolorlight=” “. CSS has some enhanced border properties that help in creating borders. The below example shows setting a single border color to the corresponding table. Here denotes table row and
denotes table data and it is started using tag. And the border for them is applied using their width and colors

Code:




Chicago new york Texas California

Output:

HTML 顏色 

Now let’s see setting two border-color separately. The below code uses table attribute with their elements.

Code:




Samsung Nokia
Apple Iphone   Xiami Redmi

Output:

HTML 顏色 

Using

tag

It is used to group all the elements and helps in view of a web page at its particular position. In the below code, we have used two

one for a paragraph and the other to implement style attribute by setting border pixels and thickness is increased by giving out the width, and we have added padding to demonstrate them to the left.

Code:





 Sample border color using div


Nature is beautiful

div with a border color.

Output:

HTML 顏色 

Example: This explains how to set the color for padding and margin using class and list tags.

Code:




Borders



  • DOM model
  • Document object model helps in creating document tree

Output:

HTML 顏色 

How to Specify Color Using Values in HTML?

The basic color values vary from 0 to 255 for red, blue, green. The color value is important in giving out lightness.

The below table shows sample values for the colors.

HTML 顏色 

Example: The below example shows different color values in their background settings.

Code:




Data Mining techniques is to understand a patterns

Classification

Prediction

Regression

Classification, Prediction techniques

HTML colors

Table colors

Output:

HTML 顏色 

How to use RGB Color Values in HTML?

RGB denotes Red, Green blue colors directly and uses the RGB function. It takes those three values as parameters and declared them as integers sometimes in percentage. Whichever color we want, its intensity is given a higher value 255 as an integer value falls between o to 255. For instance, to have a blue color, it is preferred to denote (0,0,255). here the first two values are marked as 0,0, and the last value is 255 for blue.

Example: RGB color

Code:





Norway the most beautiful place it’s a Scandinavian Country.

It is the most expensive country in the world, Oslo is the capital of this green city.

Output:

HTML 顏色 

How to Specify the Lightness of Colors in HTML?

The lightness of color is defined by the brightness we prefer; it is measured in percentage. Most web designers wish to use lightness than RGB, which can be adjusted as per the requirements. Here a black set the brightness to 0% white set to 100%. It is specified using function hsl().

Code:





Norway the most beautiful place its an Scandinavian Country.

It is the most expensive country in the world, Oslo is the capital of this green city.

Output:

HTML 顏色 

You can try with different values for color in the above example.

Conclusion – HTML Colors

Therefore, to conclude, we have seen that this has different properties. In earlier days, web development has many ways to specify colors for their website, and nowadays, the most popular colorways are RGB and Hex color codes (RGB is well-known). There are different applications where colors are implemented, like a sliding scale, color palette, etc.

以上是HTML 顏色 的詳細內容。更多資訊請關注PHP中文網其他相關文章!

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

熱門話題

Java教學
1657
14
CakePHP 教程
1415
52
Laravel 教程
1309
25
PHP教程
1257
29
C# 教程
1230
24
HTML 中的表格邊框 HTML 中的表格邊框 Sep 04, 2024 pm 04:49 PM

HTML 表格邊框指南。在這裡,我們以 HTML 中的表格邊框為例,討論定義表格邊框的多種方法。

HTML 左邊距 HTML 左邊距 Sep 04, 2024 pm 04:48 PM

HTML 左邊距指南。在這裡,我們討論 HTML margin-left 的簡要概述及其範例及其程式碼實作。

HTML 中的巢狀表 HTML 中的巢狀表 Sep 04, 2024 pm 04:49 PM

這是 HTML 中巢狀表的指南。這裡我們討論如何在表中建立表格以及對應的範例。

HTML 表格佈局 HTML 表格佈局 Sep 04, 2024 pm 04:54 PM

HTML 表格佈局指南。在這裡,我們詳細討論 HTML 表格佈局的值以及範例和輸出。

HTML 輸入佔位符 HTML 輸入佔位符 Sep 04, 2024 pm 04:54 PM

HTML 輸入佔位符指南。在這裡,我們討論 HTML 輸入佔位符的範例以及程式碼和輸出。

HTML 有序列表 HTML 有序列表 Sep 04, 2024 pm 04:43 PM

HTML 有序列表指南。在這裡我們也分別討論了 HTML 有序列表和類型的介紹以及它們的範例

您如何在PHP中解析和處理HTML/XML? 您如何在PHP中解析和處理HTML/XML? Feb 07, 2025 am 11:57 AM

本教程演示瞭如何使用PHP有效地處理XML文檔。 XML(可擴展的標記語言)是一種用於人類可讀性和機器解析的多功能文本標記語言。它通常用於數據存儲

HTML onclick 按鈕 HTML onclick 按鈕 Sep 04, 2024 pm 04:49 PM

HTML onclick 按鈕指南。這裡我們分別討論它們的介紹、工作原理、範例以及各個事件中的onclick事件。

See all articles