สีเส้นขอบ CSS


สารบัญ

    แสดงสารบัญ


สีเส้นขอบ CSS

คุณสมบัติ class="w3-codespan">border-color ใช้เพื่อกำหนดสีของเส้นขอบทั้งสี่

สามารถกำหนดสีได้โดย:

  • ชื่อ - ระบุชื่อสี เช่น "สีแดง"

  • HEX - ระบุค่า HEX เช่น "ff0000"

  • RGB - ระบุค่า RGB เช่น "rgb(255,0,0)"

  • HSL - ระบุค่า HSL เช่น "hsl(0, 100%, 50%)"

  • โปร่งใส

หมายเหตุ: หากไม่ได้ตั้งค่า class="w3-codespan">border-color ก็จะสืบทอดสีขององค์ประกอบ

ตัวอย่าง

การสาธิตสีเส้นขอบแบบต่างๆ:

p.one
{
   
border-style: solid;
   
border-color: red;
}

p.two
{
   
border-style: solid;
  border-color: green;
}
p.three {
  border-style: dotted;
  border-color: 
  blue;
}

ผลลัพธ์ :

Red border
Green border
Blue border

ลองด้วยตัวคุณเอง →

<!DOCTYPE html>
<html>
<head>
<style>
p.one {
  border-style: solid;
  border-color: red;
}

p.two {
  border-style: solid;
  border-color: green;
} 

p.three {
  border-style: dotted;
  border-color: blue;
} 
</style>
</head>
<body>

<h2>The border-color Property</h2>
<p>This property specifies the color of the four borders:</p>

<p class="one">A solid red border</p>
<p class="two">A solid green border</p>
<p class="three">A dotted blue border</p>

<p><b>Note:</b> The "border-color" property does not work if it is used alone. Use the "border-style" property to set the borders first.</p>

</body>
</html>



สีข้างเฉพาะ

คุณสมบัติ class="w3-codespan">border-color สามารถมีค่าได้ตั้งแต่หนึ่งถึงสี่ค่า (สำหรับ ขอบบน ขอบขวา ขอบล่าง และขอบซ้าย)

ตัวอย่าง

 p.one {
  border-style: solid;
  border-color: red green blue yellow; 
  /* red top, green right, blue bottom and yellow left */
}

ลองด้วยตัวคุณเอง →

<!DOCTYPE html>
<html>
<head>
<style>
p.one {
  border-style: solid;
  border-color: red green blue yellow; /* red top, green right, blue bottom and yellow left */
}
</style>
</head>
<body>

<h2>The border-color Property</h2>
<p>The border-color property can have from one to four values (for the top border, right border, bottom border, and the left border):</p>

<p class="one">A solid multicolor border</p>

</body>
</html>




ค่าฐานสิบหก

สีของเส้นขอบสามารถระบุได้โดยใช้ค่าเลขฐานสิบหก (HEX):

ตัวอย่าง

 p.one {
  border-style: solid;
  border-color: #ff0000; /* red 
  */
}

ลองด้วยตัวคุณเอง →

<!DOCTYPE html>
<html>
<head>
<style>
p.one {
  border-style: solid;
  border-color: #ff0000; /* red */
}

p.two {
  border-style: solid;
  border-color: #0000ff; /* blue */
}

p.three {
  border-style: solid;
  border-color: #bbbbbb; /* grey */
}
</style>
</head>
<body>

<h2>The border-color Property</h2>
<p>The color of the border can also be specified using a hexadecimal value (HEX):</p>

<p class="one">A solid red border</p>
<p class="two">A solid blue border</p>
<p class="three">A solid grey border</p>

</body>
</html>



ค่า RGB

หรือโดยใช้ค่า RGB:

ตัวอย่าง

 p.one {
  border-style: solid;
  border-color: rgb(255, 0, 0); 
  /* red */
}

ลองด้วยตัวคุณเอง →

<!DOCTYPE html>
<html>
<head>
<style>
p.one {
  border-style: solid;
  border-color: rgb(255, 0, 0); /* red */
}

p.two {
  border-style: solid;
  border-color: rgb(0, 0, 255); /* blue */
}

p.three {
  border-style: solid;
  border-color: rgb(187, 187, 187); /* grey */
}
</style>
</head>
<body>

<h2>The border-color Property</h2>
<p>The color of the border can also be specified using RGB values:</p>

<p class="one">A solid red border</p>
<p class="two">A solid blue border</p>
<p class="three">A solid grey border</p>

</body>
</html>



ค่า HSL

คุณยังสามารถใช้ค่า HSL:

ตัวอย่าง

 p.one {
  border-style: solid;
  border-color: hsl(0, 100%, 50%); 
  /* red */
}

ลองด้วยตัวคุณเอง →

<!DOCTYPE html>
<html>
<head>
<style>
p.one {
  border-style: solid;
  border-color: hsl(0, 100%, 50%); /* red */
}

p.two {
  border-style: solid;
  border-color: hsl(240, 100%, 50%); /* blue */
}

p.three {
  border-style: solid;
  border-color: hsl(0, 0%, 73%); /* grey */
}
</style>
</head>
<body>

<h2>The border-color Property</h2>
<p>The color of the border can also be specified using HSL values:</p>

<p class="one">A solid red border</p>
<p class="two">A solid blue border</p>
<p class="three">A solid grey border</p>

</body>
</html>


คุณสามารถเรียนรู้เพิ่มเติมเกี่ยวกับค่า HEX, RGB และ HSL ได้ในบทสี CSS ของเรา