當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


HTML Style borderTopLeftRadius用法及代碼示例


DOM樣式borderTopLeftRadius屬性用於設置或返回元素左上邊界的半徑。

用法:

  • 獲取borderTopLeftRadius屬性
    object.style.borderTopLeftRadius
  • 設置borderTopLeftRadius屬性
    object.style.borderTopLeftRadius = "length | percentage | 
    initial | inherit"

屬性值:


  1. length:用於定義固定長度單位的半徑。可以使用兩個值來指定四分之一橢圓的半徑,第一個值是水平半徑,第二個值是垂直半徑。

    示例1:使用一個值指定半徑。

    <!DOCTYPE html> 
    <html lang="en"> 
      
    <head> 
        <title> 
            DOM Style BorderTopLeftRadius 
        </title> 
      
        <style> 
            .elem { 
                padding:10px; 
                border-style:solid; 
            } 
        </style> 
    </head> 
      
    <body> 
        <h1 style="color:green"> 
          GeeksforGeeks 
        </h1> 
        <b> 
          DOM Style BorderTopLeftRadius 
        </b> 
        <p class="elem"> 
            GeeksforGeeks is a computer science portal 
          with a huge variety of well written and  
          explained computer science and programming  
          articles, quizzes and interview questions. 
        </p> 
        <button onclick="changeRadius()"> 
          Change borderTopLeftRadius 
        </button> 
      
        <!-- Script to change borderTopLeftRadius -->
        <script> 
            function changeRadius() { 
                elem = document.querySelector('.elem'); 
                elem.style.borderTopLeftRadius = '30px'; 
            } 
        </script> 
    </body> 
      
    </html>

    輸出:

    在單擊按鈕之前:

    length-one-before

    單擊按鈕後:

    length-one-after

    示例2:使用兩個值指定半徑。

    <!DOCTYPE html> 
    <html lang="en"> 
      
    <head> 
        <title> 
            DOM Style BorderTopLeftRadius 
        </title> 
        <style> 
            .elem { 
                padding:10px; 
                border-style:solid; 
            } 
        </style> 
    </head> 
      
    <body> 
        <h1 style="color:green"> 
          GeeksforGeeks 
        </h1> 
        <b> 
          DOM Style BorderTopLeftRadius 
        </b> 
        <p class="elem"> 
          GeeksforGeeks is a computer science portal 
          with a huge variety of well written and 
          explained computer science and programming 
          articles, quizzes and interview questions. 
        </p> 
        <button onclick="changeRadius()"> 
          Change borderTopLeftRadius 
        </button> 
      
        <!-- Script to change borderTopLeftRadius -->
        <script> 
            function changeRadius() { 
                elem = document.querySelector('.elem'); 
                elem.style.borderTopLeftRadius = '30px 60px'; 
            } 
        </script> 
    </body> 
      
    </html>

    輸出:

    在單擊按鈕之前:

    length-two-before


    單擊按鈕後:

    length-two-after

  2. percentage:這用於以百分比為單位定義半徑。可以使用兩個值來指定四分之一橢圓的半徑,第一個值是水平半徑,它是邊框的寬度的百分比,第二個值是垂直半徑,是border-box的高度的百分比。

    示例3:使用一個值指定半徑。

    <!DOCTYPE html> 
    <html lang="en"> 
      
    <head> 
        <title> 
            DOM Style BorderTopLeftRadius 
        </title> 
        <style> 
            .elem { 
                padding:10px; 
                border-style:solid; 
            } 
        </style> 
    </head> 
      
    <body> 
        <h1 style="color:green"> 
          GeeksforGeeks 
        </h1> 
        <b> 
          DOM Style BorderTopLeftRadius 
        </b> 
        <p class="elem"> 
          GeeksforGeeks is a computer science 
          portal with a huge variety of well  
          written and explained computer  
          science and programming articles,  
          quizzes and interview questions. 
        </p> 
        <button onclick="changeRadius()"> 
          Change borderTopLeftRadius 
        </button> 
      
        <!-- Script to change borderTopLeftRadius -->
        <script> 
            function changeRadius() { 
                elem = document.querySelector('.elem'); 
                elem.style.borderTopLeftRadius = '20%'; 
            } 
        </script> 
    </body> 
      
    </html>

    輸出:

    在單擊按鈕之前:

    percentage-one-before

    單擊按鈕後:

    percentage-one-after

    示例4:使用兩個值指定半徑。

    <!DOCTYPE html> 
    <html lang="en"> 
      
    <head> 
        <title> 
            DOM Style BorderTopLeftRadius 
        </title> 
        <style> 
            .elem { 
                padding:10px; 
                border-style:solid; 
            } 
        </style> 
    </head> 
      
    <body> 
        <h1 style="color:green"> 
          GeeksforGeeks 
        </h1> 
        <b> 
          DOM Style BorderTopLeftRadius 
        </b> 
        <p class="elem"> 
         GeeksforGeeks is a computer science portal 
          with a huge variety of well written and  
          explained computer science and programming 
          articles, quizzes and interview questions. 
        </p> 
        <button onclick="changeRadius()"> 
          Change borderTopLeftRadius 
        </button> 
      
        <!-- Script to change borderTopLeftRadius -->
        <script> 
            function changeRadius() { 
                elem = document.querySelector('.elem'); 
                elem.style.borderTopLeftRadius = '30% 90%'; 
            } 
        </script> 
    </body> 
      
    </html>

    輸出:


    在單擊按鈕之前:

    percentage-two-before

    單擊按鈕後:

    percentage-two-after

  3. initial:這用於將此屬性設置為其默認值。

    示例5:

    <!DOCTYPE html> 
    <html lang="en"> 
      
    <head> 
        <title> 
            DOM Style BorderTopLeftRadius 
        </title> 
        <style> 
            .elem { 
                padding:10px; 
                border-style:solid; 
                border-top-left-radius:30px; 
            } 
        </style> 
    </head> 
      
    <body> 
        <h1 style="color:green"> 
          GeeksforGeeks 
        </h1> 
        <b> 
          DOM Style BorderTopLeftRadius 
        </b> 
        <p class="elem"> 
          GeeksforGeeks is a computer science portal 
          with a huge variety of well written and  
          explained computer science and programming  
          articles, quizzes and interview questions. 
        </p> 
        <button onclick="changeRadius()"> 
          Change borderTopLeftRadius 
        </button> 
      
        <!-- Script to change borderTopLeftRadius -->
        <script> 
            function changeRadius() { 
                elem = document.querySelector('.elem'); 
                elem.style.borderTopLeftRadius = 'initial'; 
            } 
        </script> 
    </body> 
      
    </html>

    輸出:

    在單擊按鈕之前:

    initial-before

    單擊按鈕後:

    initial-after


  4. 繼承6:這將從其父項繼承該屬性。

    例:

    <!DOCTYPE html> 
    <html lang="en"> 
      
    <head> 
        <title> 
            DOM Style BorderTopLeftRadius 
        </title> 
        <style> 
            #parent { 
                padding:10px; 
                border-style:solid; 
                /* Setting the borderTopLeftRadius of the parent */ 
                border-top-left-radius:30px; 
            } 
              
            .elem { 
                padding:10px; 
                border-style:solid; 
            } 
        </style> 
    </head> 
      
    <body> 
        <h1 style="color:green"> 
          GeeksforGeeks 
        </h1> 
        <b> 
          DOM Style BorderTopLeftRadius 
        </b> 
        <br> 
        <br> 
        <div id="parent"> 
            <p class="elem"> 
              GeeksforGeeks is a computer science portal 
              with a huge variety of well written and  
              explained computer science and programming 
              articles, quizzes and interview questions. 
            </p> 
        </div> 
        <br> 
        <button onclick="changeRadius()"> 
          Change borderTopLeftRadius 
        </button> 
      
        <!-- Script to change borderTopLeftRadius -->
        <script> 
            function changeRadius() { 
                elem = document.querySelector('.elem'); 
                elem.style.borderTopLeftRadius = 'inherit'; 
            } 
        </script> 
    </body> 
      
    </html>

    輸出:

    在單擊按鈕之前:

    inherit-before

    單擊按鈕後:

    inherit-after

支持的瀏覽器:borderTopLeftRadius屬性支持的瀏覽器如下:

  • 穀歌瀏覽器
  • Internet Explorer 9.0
  • Firefox
  • Opera
  • 蘋果Safari


相關用法


注:本文由純淨天空篩選整理自sayantanm19大神的英文原創作品 HTML | DOM Style borderTopLeftRadius Property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。