Computer >> คอมพิวเตอร์ >  >> การเขียนโปรแกรม >> CSS

การตั้งค่าคุณสมบัติสีใน CSS


เราสามารถกำหนดสีสำหรับข้อความ เส้นขอบ และพื้นหลังขององค์ประกอบโดยใช้ CSS คุณสมบัติสีใช้เพื่อระบุสีข้อความสำหรับองค์ประกอบ

ไวยากรณ์

ไวยากรณ์สำหรับคุณสมบัติสี CSS มีดังต่อไปนี้ -

Selector {
   color: /*value*/
}

ตัวอย่างต่อไปนี้แสดงคุณสมบัติสี CSS -

ตัวอย่าง

<!DOCTYPE html>
<html>
<head>
<style>
div {
   color: seashell;
   background-color: lightcoral;
}
p {
   font-size: 1.5em;
   color: blue;
   background-color: palegreen;
   box-shadow: 0 0 5px 1px rgb(0,0,0);
}
</style>
</head>
<body>
<div>
This is demo text.
<p>
Text added for reference.
</p>
This is demo text 2.
</div>
</body>
</html>

ผลลัพธ์

สิ่งนี้ให้ผลลัพธ์ต่อไปนี้ -

การตั้งค่าคุณสมบัติสีใน CSS

ตัวอย่าง

<!DOCTYPE html>
<html>
<head>
<style>
* {
   text-align: center;
}
h3 {
   color: red;
   border: 2px ridge rosybrown;
}
p {
   color: royalblue;
   background-color: cornsilk;
   box-shadow: 0 0 5px 1px deeppink;
}
</style>
</head>
<body>
<h3>Demo Demo Demo Demo</h3>
<p>Demo text here</p>
</body>
</html>

ผลลัพธ์

สิ่งนี้ให้ผลลัพธ์ต่อไปนี้ -

การตั้งค่าคุณสมบัติสีใน CSS