当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。