คุณสมบัติ HTML DOM borderRadius ใช้เพื่อเพิ่มมุมโค้งมนให้กับทั้งสี่ด้านขององค์ประกอบ เมื่อใช้คุณสมบัตินี้ เราสามารถตั้งค่าและรับคุณสมบัติรัศมีเส้นขอบ เช่น borderTopLeftRadius, borderTopRightRadius, borderBottomRightRadius, borderBottomLeftRadius
ต่อไปนี้เป็นไวยากรณ์สำหรับ −
การตั้งค่าคุณสมบัติ borderRadius:
object.style.borderRadius = "1-4 length|% / 1-4 length|%|initial|inherit"
ค่าคุณสมบัติอธิบายได้ดังนี้ -
| ค่า | คำอธิบาย |
|---|---|
| ความยาว | สำหรับกำหนดรูปร่างเส้นขอบ |
| % | สำหรับกำหนดรูปร่างเส้นขอบเป็นเปอร์เซ็นต์ |
| เริ่มต้น | สำหรับการตั้งค่าคุณสมบัตินี้เป็นค่าเริ่มต้น |
| สืบทอด | การสืบทอดค่าคุณสมบัติหลัก |
ให้เราดูตัวอย่างคุณสมบัติ borderRadius -
ตัวอย่าง
<!DOCTYPE html>
<html>
<head>
<style>
#DIV1{
height: 100px;
width: 200px;
border: 10px groove orange;
padding: 10px;
border-radius: 1px 1px 1px 1px;
}
</style>
<script>
function changeBorderRadius(){
document.getElementById("DIV1").style.borderRadius="45px 45px 45px 45px";
document.getElementById("Sample").innerHTML="The border radius for the four borders of the above div are now increased";
}
</script>
</head>
<body>
<div id="DIV1">SOME SAMPLE TEXT</div>
<p>Increase the above div border radius size by clicking the below button</p>
<button onclick="changeBorderRadius()">Change Border Radius</button>
<p id="Sample"></p>
</body>
</html> ผลลัพธ์

เมื่อคลิกปุ่ม "เปลี่ยนรัศมีเส้นขอบ" -
