Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> HTML

คุณสมบัติ borderRightColor ของ HTML DOM Style: สีขอบขวา

คุณสมบัติ borderRightColor ใช้สำหรับกำหนดหรือดึงค่าสีของขอบด้านขวาขององค์ประกอบ

ไวยากรณ์ (Syntax)

object.style.borderRightColor = "color|transparent|initial|inherit"

ค่าที่รองรับ

ค่าคำอธิบาย
colorระบุสีขอบขวา (ชื่อสี, HEX, RGB, RGBA, HSL, HSLA) ค่าเริ่มต้น = ดำ
transparentทำให้ขอบขวาโปร่งใส
initialตั้งค่ากลับเป็นค่าเริ่มต้น (ดำ)
inheritสืบทอดสีจากพาเรนต์

ตัวอย่างการใช้งาน

<!DOCTYPE html>
<html>
<head>
<style>
  #IMG1 {
    border-right: solid 8px;
    border-right-color: orange;
  }
</style>
<script>
  function changeBorderRight() {
    document.getElementById("IMG1").style.borderRightColor = "lightgreen";
    document.getElementById("Sample").innerHTML = "สีขอบขวาถูกเปลี่ยนเป็นสีเขียวอ่อนแล้ว";
  }
</script>
</head>
<body>
<img id="IMG1" src="https://www.tutorialspoint.com/blue_prism/images/blueprism-logo.jpg" alt="Blue Prism Logo">
<p>คลิกปุ่มเพื่อเปลี่ยนสีขอบขวาของรูปภาพด้านบน</p>
<button onclick="changeBorderRight()">เปลี่ยนสีขอบ</button>
<p id="Sample"></p>
</body>
</html>

ผลลัพธ์

ก่อน: ขอบขวาสีส้ม
หลัง: ขอบขวาสีเขียวอ่อน

⚠️ ข้อผิดพลาดในโค้ดตัวอย่างเดิม (Fixed)

โค้ดตัวอย่างเดิมมีข้อผิดพลาด: ใช้ borderLeftColor แทน borderRightColor และข้อความ "left" แทน "right" - ได้แก้ไขแล้วในตัวอย่างข้างต้น

รูปแบบสีที่รองรับ

รูปแบบตัวอย่าง
ชื่อสีred, blue, lightgreen
HEX#ff0000, #00ff00
RGBrgb(255, 0, 0)
RGBArgba(255, 0, 0, 0.5)
HSLhsl(0, 100%, 50%)
HSLAhsla(0, 100%, 50%, 0.5)

คุณสมบัติขอบด้านอื่นที่เกี่ยวข้อง

  • borderLeftColor, borderTopColor, borderBottomColor
  • borderColor - Shorthand สำหรับทั้ง 4 ด้าน

หมายเหตุ

  • ต้องมี border-right-style ไม่ใช่ none และ border-right-width > 0
  • transparent เหมาะสำหรับสร้างรูปสามเหลี่ยม CSS
  • ถ้าไม่ระบุสี จะใช้ค่า color (สีข้อความ) ขององค์ประกอบ