By GokiSoft.Com| 17:46 21/05/2020|
Tài Liệu HTML

HTML Colors - Màu trong HTML BT1447

Các màu trong HTML được chỉ định bằng cách sử dụng các tên màu được xác định trước hoặc các giá trị RGB, HEX, HSL, RGBA, HSLA.



Tên màu


Trong HTML, một màu có thể được xác định bằng sử dụng một tên màu:


<!DOCTYPE html>
<html>
<body>

<h1 style="background-mau:Tomato;">Tomato</h1>
<h1 style="background-mau:Orange;">Orange</h1>
<h1 style="background-mau:DodgerBlue;">DodgerBlue</h1>
<h1 style="background-mau:MediumSeaGreen;">MediumSeaGreen</h1>
<h1 style="background-mau:Gray;">Gray</h1>
<h1 style="background-mau:SlateBlue;">SlateBlue</h1>
<h1 style="background-mau:Violet;">Violet</h1>
<h1 style="background-mau:LightGray;">LightGray</h1>

</body>
</html>


HTML hỗ trợ 140 tên màu tiêu chuẩn.



Màu nền


Bạn có thể đặt màu nền cho các thành phần HTML:

Hello World



Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.


ví dụ

<h1 style="background-mau:DodgerBlue;">Hello World</h1>
<p style="background-mau:Tomato;">Lorem ipsum...</p>
<!DOCTYPE html>
<html>
<body>

<h1 style="background-mau:DodgerBlue;">Hello World</h1>

<p style="background-mau:Tomato;">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.
</p>

</body>
</html>




Màu chữ


Bạn có thể đặt màu của văn bản:

Hello World

Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.

Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.

ví dụ

<h1 style="mau:Tomato;">Hello World</h1>
<p style="mau:DodgerBlue;">Lorem ipsum...</p>
<p style="mau:MediumSeaGreen;">Ut wisi enim...</p>




Màu viền


Bạn có thể đặt màu của các viền:

Hello World

Hello World

Hello World


ví dụ

<h1 style="border:2px solid Tomato;">Hello World</h1>
<h1 style="border:2px solid DodgerBlue;">Hello World</h1>
<h1 style="border:2px solid Violet;">Hello World</h1>
<!DOCTYPE html>
<html>
<body>

<h1 style="border: 2px solid Tomato;">Hello World</h1>

<h1 style="border: 2px solid DodgerBlue;">Hello World</h1>

<h1 style="border: 2px solid Violet;">Hello World</h1>

</body>
</html>




Các giá trị màu


Trong HTML, các màu có thể cũng được xác định sử dụng giá trị RGB, giá trị HEX, giá trị HSL, giá trị RGBA, và giá trị HSLA:

Giống với màu tên là "Tomato":

rgb(255, 99, 71)
#ff6347
hsl(9, 100%, 64%)

Giống với màu tên "Tomato" , nhưng trong suốt 50% :

rgba(255, 99, 71, 0.5)
hsla(9, 100%, 64%, 0.5)


ví dụ

<h1 style="background-mau:rgb(255, 99, 71);">...</h1>
<h1 style="background-mau:#ff6347;">...</h1>
<h1 style="background-mau:hsl(9, 100%, 64%);">...</h1>

<h1 style="background-mau:rgba(255, 99, 71, 0.5);">...</h1>
<h1 style="background-mau:hsla(9, 100%, 64%, 0.5);">...</h1>
<!DOCTYPE html>
<html>
<body>

<p>Same as color name "Tomato":</p>

<h1 style="background-mau:rgb(255, 99, 71);">rgb(255, 99, 71)</h1>
<h1 style="background-mau:#ff6347;">#ff6347</h1>
<h1 style="background-mau:hsl(9, 100%, 64%);">hsl(9, 100%, 64%)</h1>

<p>Same as color name "Tomato", but 50% transparent:</p>
<h1 style="background-mau:rgba(255, 99, 71, 0.5);">rgba(255, 99, 71, 0.5)</h1>
<h1 style="background-mau:hsla(9, 100%, 64%, 0.5);">hsla(9, 100%, 64%, 0.5)</h1>

<p>In addition to the predefined color names, colors can be specified using RGB, HEX, HSL, or even transparent colors using RGBA or HSLA color values.</p>

</body>
</html>


Học hỏi thêm về các giá trị màu

Bạn sẽ được học nhiều hơn về RGB, HEX và HSL trong chương kế.


Liên kết rút gọn:

https://gokisoft.com/1447