Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> CSS

Đặt màu chữ với CSS color


Để đặt màu chữ, dùng thuộc tính color trong CSS. Bạn có thể đặt màu bằng tên màu, giá trị hex, RGB, hoặc HSL.

Ví dụ

<!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>

Kết quả

Đặt màu chữ với CSS color

Ví dụ khác

<!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>

Kết quả

Đặt màu chữ với CSS color