HTML - DOM Style 物件 borderRadius 屬性



HTML DOM Style 物件 'borderRadius' 屬性用作簡寫屬性,它設定或返回四個不同的 borderRadius 屬性,它們分別是 **borderTopLeftRadius**、**borderTopRightRadius**、**borderBottomRightRadius** 和 **borderBottomLeftRadius**。

語法

以下是獲取或設定 borderRadius 屬性的語法。

設定 borderRadius 屬性
object.style.borderRadius= "1-4 length | % / 1-4 length|%| initial | inherit";
獲取 borderRadius 屬性
object.style.borderRadius;

屬性值

描述
長度 它指定邊框形狀。
百分比 它以百分比指定邊框形狀。
初始 它用於將此屬性設定為其預設值。
繼承 它用於繼承其父元素的屬性。

返回值

它返回一個字串值,表示元素的邊框半徑屬性。

HTML DOM Style 物件 'borderRadius' 屬性示例

以下示例說明如何使用長度值和百分比值新增邊框半徑。

<!DOCTYPE html>
<html lang="en">
<head>
    <title>
        HTML DOM Style Object borderRadius Property
    </title>
    <style>
        section {
            border: aqua 2px solid;
            height: 400px;
            width: 400px;
        }
    </style>
</head>
<body>
    <p>
        Click to add or change the border radius.
    </p>
    <button onclick="fun()">Add</button>
    <button onclick="funTwo()">Change</button>
    <section id="border">
        Welcome to Tutorials Point...
    </section>
    <script>
        function fun() {
            document.getElementById("border")
            .style.borderRadius = "25px";
        }
        function funTwo() {
            document.getElementById("border")
            .style.borderRadius = "15%";
        }
    </script>
</body>
</html>

支援的瀏覽器

屬性 Chrome Edge Firefox Safari Opera
borderRadius 是 4 是 12 是 4 是 5 是 10.5
html_dom_style_object_reference.htm
廣告